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.
The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).
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.
3 2 2
1 1 2
1 2 1
3 2 1
-1
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 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~