Codeforces 459c pashmak and buses wit math

Source: Internet
Author: User

There are n people, K buses, M days, and N people are arranged to take the bus every day (there can be empty buses ), in order to make these N people not friends, as long as each person takes at least one day on the m-day bus, it will be OK.

I want you to determine whether there is such an arrangement. If so, I will output a specific arrangement scheme for everyone to take that car every day.

I did not think of any good questions at all .. Really, although it was so simple to scream after knowing it, at first I was really confused. Now it is clear that every student's vehicle in the M-day will form a series composed of M numbers (1-K stands for the bus number ), according to the question requirements, only the sequence of students is unique.

Then, we only need to convert the meaning of the question into a sequence composed of n Different M numbers (as long as there is a number that is different), then we will put this sequence, the K-base number of a m-bit is not enough, starting from 111111 every time ..

Start enumeration, always enumeration to kkkkkk... It's over... Ah, it's really witty.

Of course, at the beginning, you can directly take a ride to determine whether the M k-in-number is greater than or equal to N. If the M k-in-number is not enough, you can use a high-precision addition method to obtain the sequence and then output it.

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define LL __int64using namespace std;LL n,k,d;int ans[1010][1010];int main(){    while (scanf("%I64d%I64d%I64d",&n,&k,&d)!=EOF)    {        LL tmp=k;        for (LL i=2;i<=d;i++){            tmp=tmp*k;            if (tmp>=n) break;        }        if (tmp<n){            puts("-1");            continue;        }        for (int i=d;i>=1;i--) ans[0][i]=1;        ans[0][d]=0;        for (int i=1;i<=n;i++){            int c=0;            ans[i][d]=ans[i-1][d]+1;            if (ans[i][d]>k){ans[i][d]=1;c++;}            for (int j=d-1;j>=1;j--){                ans[i][j]=ans[i-1][j]+c;                if (ans[i][j]>k){                    c=1;                    ans[i][j]=1;                }                else c=0;            }        }        for (int i=1;i<=d;i++){            printf("%d",ans[1][i]);            for (int j=2;j<=n;j++){                printf(" %d",ans[j][i]);            }            puts("");        }    }    return 0;}

 

Codeforces 459c pashmak and buses wit math

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.