cf 459c Pashmak and Buses
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Recently Pashmak has been employed in a transportation company. The company has k buses 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 n integers. The j-th integer of the i-th line shows which bus the j-th student has to take on the i-th day. You can assume that the buses are numbered from 1 to k.
Sample Input
3 2 2
1 1 2
1 2 1
3 2 1
-1
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<fstream>
#include<cstring>
using namespace std;
int code[][];
int main()
{
int n,k,d;
//cout<<1000*log10(1000000000+0.0)<<endl;
//cout<<pow(5,4)<<endl;
while(~scanf("%d%d%d",&n,&k,&d))
{
int tmp;
int flag=k;
for(int i=;i<d-;i++)
{
if(flag>n) break;
flag*=k; }
//cout<<flag;
if(flag<n)
{
printf("-1\n");
continue;
}
tmp= (pow(n+0.0,1.0/d)>(int)pow(n+0.0,1.0/d))?(int)pow(n+0.0,1.0/d)+:(int)pow(n+0.0,1.0/d);
for(int j=;j<d;j++)
code[j][]=code[j][]=;
for(int i=; i<n; i++)
{
int j=d-; //cout<<"ss";
code[j][i]++;
int now=code[j][i];
int row=j;
int col=i;
while(now>tmp-&&row>-)
{
code[row][col]=now%(tmp);
code[row-][col]+=(now/(tmp));
now=code[row-][col];
row--;
}
for(int j=;j<d;j++)
code[j][i+]=code[j][i];
}
for(int i=; i<d; i++)
{
for(int j=; j<n; j++)
{
cout<<code[i][j]+<<" ";
}
cout<<endl;
}
}
return ;
}
这里
for(int i=0;i<d-1;i++)
{
if(flag>n) break;
flag*=k;
}
如果用pow的话,存在两个问题:1 pow(1e9,1000)过大 2 由于精度问题,有些数的比较是失败的
cf 459c Pashmak and Buses的更多相关文章
- CodeForces - 459C - Pashmak and Buses
先上题目+: C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces 459C Pashmak and Buses 解题报告
题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...
- codeforces 459C Pashmak and Buses(模拟,组合数A)
题目 跑个案例看看结果就知道了:8 2 3 题目给的数据是 n,k,d 相当于高中数学题:k个人中选择d个人排成一列,有多少种不同的方案数,列出其中n中就可以了. #include<iostre ...
- CodeForces 459C Pashmak and Buses(构造)题解
题意:n个人,k辆车,要求d天内任意两人都不能一直在同一辆车,能做到给出构造,不能输出-1 思路:我们把某一个人这d天的车号看成一个d位的数字,比如 1 1 2 3代表第一天1号车.第二天1号车.第三 ...
- Codeforces 459C Pashmak and Buses 机智数学题
这个题目说的是有n个人,有k辆巴士,有m天,每天都要安排n个人坐巴士(可以有巴士为空),为了使得这n个人不会成为朋友,只要每两个人在这m天里坐的巴士至少一天不相同即可. 要你求是否有这样的安排方法,如 ...
- CF459C Pashmak and Buses (构造d位k进制数
C - Pashmak and Buses Codeforces Round #261 (Div. 2) C. Pashmak and Buses time limit per test 1 seco ...
- cf459C Pashmak and Buses
C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- CF 459A(Pashmak and Garden-正方形给出2点求2点)
A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standar ...
随机推荐
- PHP-Java-Bridge使用笔记
最近因为需要封装一个jar包供php调用,在网上搜索了下,基本上讲都是使用php-java-bridge,说实话,网上的教程有很多是不行的,但是功夫不负有心人,找到了一篇文章,也很感谢那篇文章的作者, ...
- leetcode mock Shuffle an Array
1. shuffle算法: http://www.cnblogs.com/huaping-audio/archive/2008/09/09/1287985.html 注意:我们一般用的是第二种swap ...
- environmentmap in unity
真崩溃之前明明找到这个api了 然后没存 然后我就找不到了... 刚刚遇到个特别邪门的问题 调着调着 vs的断点都显示无效 重启unity vs 电脑都不好使 之后我双击了breakpoint窗口.. ...
- 如何为Failover Cluster添加Quorum disk
无废话, 上图.
- java设计模式2--抽象工厂模式(Abstract Factory)
本文地址:http://www.cnblogs.com/archimedes/p/java-abstract-factory-pattern.html,转载请注明源地址. 抽象工厂模式(别名:配套) ...
- DHCP安装配置详解
DHCP基于客户/服务器模式.当DHCP客户端启动时,它会自动与DHCP服务器通信,由DHCP服务器为DHCP客户端提供自动分配IP地址的服务. 当然高级的DHCP,不光只是分配地址这么简单,今天我们 ...
- Transform数据权限浅析1之mdl语句批量加载权限
Cognos建模工具除了Framework之外,还有一个Transform,两者的最大区别就是在于Framework是通过结构直连关系数据库的,数据根据数据仓库的变化而变化,而Transform是生产 ...
- wifidog 移植到MIPS平台
使用的是一款Broadcom的芯片,现在上面运行wifidog实现认证上网的功能.由于不是openwrt平台,所以就没了make menuconfig 勾选就能自动编译到版本中的.所以想使用交叉编译的 ...
- Web版RSS阅读器(五)——初步完成阅读功能
上一篇博文<Web版RSS阅读器(四)——定制自己的Rss解析库myrsslib4j>中,已经分享给大家制作自己的rss解析库.稍微有点遗憾的是,它仅仅支持rss格式的博客.现在给大家分享 ...
- 自己定义iOS上双击Home键图切换
假设双击Home.会来到iOS App的switcher页面,在这儿列出了当前系统挂起的App, 上面有每一个App的切屏,相信大家都熟悉这个东东了. 它事实上是每一个App在挂起前,对App后个载屏 ...