zoukankan      html  css  js  c++  java
  • Codeforces Round #261 (Div. 2) C

    Description

    Recently Pashmak has been employed in a transportation company. The company has kbuses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all d days.

    Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity.

    Input

    The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).

    Output

    If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print nintegers. The j-th integer of the i-th line shows which bus the j-th student has to take on thei-th day. You can assume that the buses are numbered from 1 to k.

    Examples
    input
    3 2 2
    output
    1 1 2 
    1 2 1
    input
    3 2 1
    output
    -1
    Note

    Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day.

    题意:有K台公交,n个人,d天,任意两个人全部d天都不能做同一辆公交,输出这种安排

    解法:K台公交安排d天,自然是Kd种方法,Ki大于等于n说明符合要求,再将1~n变成k进制保证题目要求,然后按照题目要求输出

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define ll long long
     4 ll Pow(ll a,ll b)
     5 {
     6     ll ans=1;
     7     ll base=a;
     8     while(b)
     9     {
    10         if(b&1)
    11         {
    12             ans*=base;
    13         }
    14         base*=base;
    15         b>>=1;
    16     }
    17     return ans;
    18 }
    19 ll n,k,d;
    20 ll solve[2000][2000];
    21 int main()
    22 {
    23     int flag=0;
    24     cin>>n>>k>>d;
    25     for(int i=1;i<=d;i++)
    26     {
    27         if(Pow(k,i)>=n)
    28         {
    29             flag=1;
    30             break;
    31         }
    32     }
    33     if(flag)
    34     {
    35         for(int i=1;i<=n;i++)
    36         {
    37             ll num=i;
    38             for(int j=1;j<=d;j++)
    39             {
    40                 solve[i][j]=num%k+1;
    41                 num/=k;
    42             }
    43         }
    44         for(int i=1;i<=d;i++)
    45         {
    46             for(int j=1;j<=n;j++)
    47             {
    48                 cout<<solve[j][i]<<" ";
    49             }
    50             cout<<endl;
    51         }
    52     }
    53     else
    54     {
    55         cout<<"-1"<<endl;
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    一款新型的智能家居WiFi选择方案——SimpleWiFi在无线智能家居中的应用
    智能手机的工业控制应用方案——SimpleWiFi在工业控制领域应用
    一种单片机支持WiFi的应用——SimpleWiFi在单片机中的应用
    TI推出SimpleLink低能耗蓝牙CC2541
    SimpleWiFi模块评估板
    Android架构设计和软硬整合完整训练
    CentOS上解压ZIP乱码的解决办法
    更具体的描述JNI
    数据市中心全省中国mysql脚本
    几种方法枚举子集
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6582028.html
Copyright © 2011-2022 走看看