POJ-3629
Card Stacking
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3927 Accepted: 1541 Description
Bessie is playing a card game with her N-1 (2 ≤ N ≤ 100) cow friends using a deck with K (N ≤ K ≤ 100,000; K is a multiple of N) cards. The deck contains M = K/N "good" cards and K-M "bad" cards. Bessie is the dealer and, naturally, wants to deal herself all of the "good" cards. She loves winning.
Her friends suspect that she will cheat, though, so they devise a dealing system in an attempt to prevent Bessie from cheating. They tell her to deal as follows:
1. Start by dealing the card on the top of the deck to the cow to her right
2. Every time she deals a card, she must place the next P (1 ≤ P ≤ 10) cards on the bottom of the deck; and
3. Continue dealing in this manner to each player sequentially in a counterclockwise manner
Bessie, desperate to win, asks you to help her figure out where she should put the "good" cards so that she gets all of them. Notationally, the top card is card #1, next card is #2, and so on.
Input
* Line 1: Three space-separated integers: N, K, and P
Output
* Lines 1..M: Positions from top in ascending order in which Bessie should place "good" cards, such that when dealt, Bessie will obtain all good cards.
Sample Input
3 9 2Sample Output
3
7
8
题意:
Bessie跟朋友玩牌,总共n人k张牌,k是n的整数倍。k张牌中共有k/n张好牌,Bessie想要作弊得到所有好牌。可Bessie的同伴为了防止Bessie作弊而设定了如下规则:
1.每次发牌从牌顶发,从Bessie右手边第一个人开始。
2.每发出一张牌就要将接下来的p张牌依次放至牌底。
按照这个方法发完所有牌。即使是这样,Bessie依然想要拿到所有好牌,请你帮她计算出将好牌放在哪些位置可以实现Bessie的愿望。
用队列可以很方便的解决这个问题,将所有k张牌入队,发牌即为出队,过牌即出队后再入队,每循环到Bessie时将队首元素记录下来,即为好牌位置。
附AC代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
using namespace std; const int MAX=; int ans[MAX];
int main(){
int n,k,p;
queue<int> q;//定义队列
memset(ans,,sizeof(ans));
while(~scanf("%d %d %d",&n,&k,&p)){
for(int i=;i<=k;i++){//入队
q.push(i);
}
int temp=,sum=;
while(){
if(temp++%n==){//temp从1开始每循环至Bessie处则为好牌
ans[sum++]=q.front();
if(sum==k/n){//好牌放完则退出循环
break;
}
}
q.pop();//发出的牌出队
for(int i=;i<p;i++){//其他牌移到牌底
q.push(q.front());
q.pop();
}
}
sort(ans,ans+sum);
for(int i=;i<sum;i++){
printf("%d\n",ans[i]);
}
}
return ;
}
POJ-3629的更多相关文章
- POJ  3629 队列模拟
		听说STL会卡T 然后我就试了一发 哈哈哈哈哈哈哈哈哈哈 1000ms卡时过的 这很值得我写一发题解了 哈哈哈哈哈哈哈哈哈哈哈哈 //By SiriusRen #include <queue&g ... 
- CSU训练分类
		√√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ... 
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
		Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ... 
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
		Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ... 
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
		The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ... 
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
		Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ... 
- POJ 3254. Corn Fields 状态压缩DP (入门级)
		Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ... 
- POJ 2739. Sum of Consecutive Prime Numbers
		Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ... 
- POJ 2255. Tree Recovery
		Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ... 
- POJ 2752 Seek the Name, Seek the Fame [kmp]
		Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ... 
随机推荐
- 轻松搞定RabbitMQ(四)——发布/订阅
			转自 http://blog.csdn.net/xiaoxian8023/article/details/48729479 翻译地址:http://www.rabbitmq.com/tutorials ... 
- C语言各种keyword
			1.register 在函数内定义变量时.默认是 auto 类型,变量存储在内存中,当程序用到该变量时,由控制器发出指令将内存中该变量的值送到运算器,计算结束后再从运算器将数据送到内存.假设一个变量用 ... 
- ruby on rails模拟HTTP请求错误发生:end of file reached
			在文章 Ruby On Rails中REST API使用演示样例--基于云平台+云服务打造自己的在线翻译工具 中,利用ruby的Net::HTTP发起http请求訪问IBM Bluemix上的sour ... 
- java中使用opencv
			Java + opencv学习:在Eclipse下配置基于Java的OpenCV开发环境 2016-04-08 17:43 6491人阅读 评论(0) 收藏 举报 分类: OpenCV学习(10) ... 
- Fedora21 安装视频播放解码器
			12 12月 2014年12月12日 Posted by 涛儿 2 首先启用RPM Fusion软件源: sudo rpm -ivh http://download1.rpmfusion.org/fr ... 
- linux的DNS相关介绍(转载)
			1.DNS配置文件 /etc/hosts 这个是最早的 hostname 对应 IP 的档案: /etc/resolv.conf :这个重要!就是 ISP 的 DNS 服务器 IP 记录处: /e ... 
- HDU 5336 XYZ and Drops 2015 Multi-University Training Contest 4 1010
			这题的题意是给你一幅图,图里面有水滴.每一个水滴都有质量,然后再给你一个起点,他会在一開始的时候向四周发射4个小水滴,假设小水滴撞上水滴,那么他们会融合,假设质量大于4了,那么就会爆炸,向四周射出质量 ... 
- ZeroClipboard—ZeroClipboard的使用
			1.ZeroClipboard的作用: 借助Zero Clipboard能够简单高速地将内容拷贝到剪贴板,相似点击某些网页中"复制"按钮后复制对应区域的内容. 2.ZeroClip ... 
- .Net 中的反射(动态创建类型实例)
			动态创建对象 在前面节中,我们先了解了反射,然后利用反射查看了类型信息,并学习了如何创建自定义特性,并利用反射来遍历它.可以说,前面三节,我们学习的都是反射是什么,在接下来的章节中,我们将学习反射可以 ... 
- gradle找不到java目录里的mybatis的xml文件
			因为idea只编译java,gradle也默认只编译java,所以xml被忽略了. idea目前不知道如何修改,gradle修改时,需要把xml文件加上,不过gradle修改了只对gradle起作用, ... 
