POJ-3629 模拟
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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 2
Sample Output
- 3
- 7
- 8
- #include <iostream>
- #include <cstdio>
- #include <queue>
- #include <algorithm>
- using namespace std;
- int ans[];
- int main()
- {
- int n,k,p;
- while (scanf("%d%d%d",&n,&k,&p)!=EOF){
- queue<int> q;
- while (!q.empty())
- q.pop();
- for (int i=;i<=k;i++)
- q.push(i);
- int cur=;
- int sum=;
- while (!q.empty()) //模拟发牌过程,发到直至队列里没有牌
- {
- if (cur%n==){
- ans[sum]=q.front();
- sum++;
- }
- if (sum>=k/n) break;
- q.pop();
- cur++;
- for (int j=;j<p;j++)
- {
- int a=q.front();
- q.pop();
- q.push(a);
- }
- }
- sort(ans,ans+sum);
- for (int w=;w<sum;w++)
- printf("%d\n",ans[w]);
- }
- return ;
- }
POJ-3629 模拟的更多相关文章
- POJ 3629 队列模拟
听说STL会卡T 然后我就试了一发 哈哈哈哈哈哈哈哈哈哈 1000ms卡时过的 这很值得我写一发题解了 哈哈哈哈哈哈哈哈哈哈哈哈 //By SiriusRen #include <queue&g ...
- POJ 1016 模拟字符串
Numbers That Count Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20396 Accepted: 68 ...
- POJ 1208 模拟
2017-08-28 15:07:16 writer:pprp 好开心,这道题本来在集训的时候做了很长很长时间,但是还是没有做出来,但是这次的话,只花了两个小时就做出来了 好开心,这次采用的是仔细分析 ...
- POJ - 3087 模拟 [kuangbin带你飞]专题一
模拟洗牌的过程,合并两堆拍的方式:使先取s2,再取s1:分离成两堆的方式:下面C张放到s1,上面C张到s2.当前牌型与第一次相同时,说明不能搜索到答案. AC代码 #include<cstdio ...
- Shuffle'm Up POJ - 3087(模拟)
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15249 Accepted: 6962 Des ...
- poj 1379 模拟退火法
/* 模拟退火法: 找到一些随机点,从这些点出发,随机的方向坐标向外搜索: 最后找到这些随机点的最大值: 坑://if(xx>-eps&&xx<x+eps&& ...
- POJ 1471 模拟?
题意:求最大无坏点三角形 思路: 模拟? (为什么我模拟过了...) 有人用 DP,有人用 搜索... // by SiriusRen #include <cstdio> #include ...
- POJ 1951 模拟
思路: 坑爹模拟毁我一生 给两组数据: 输入: YOURE TRAVELING THROUGH ANOTHER DIMENSION A DIMENSION NOT OF SIGHT. 输出: YR T ...
- POJ 2141 模拟
思路:字符串解密 啥都告诉你了 模拟就好 //By SiriusRen #include <cstdio> #include <cstring> using namespace ...
- POJ 2459 模拟
题意: 思路: 按照题意模拟即可 //By SiriusRen #include <cstdio> using namespace std; int c,f1,f2,d,xx,yy,vis ...
随机推荐
- 实验吧-杂项-WTF?(python 01代码转图片)
比较新的题型了吧. code为base64码,转码出来是01代码,直接蒙圈,查阅相关wp才知道是转图片的. 复制到编辑器里可以看到一共65536个数字,开方是256,于是这就是一个方形的图片了–> ...
- P1071 小赌怡情
P1071 小赌怡情 转跳点:
- iOS中html打开APP传参
1.在项目info.plist中添加URL Types以供html调用 2.html代码 <html> <head lang="en"> <meta ...
- Docker 学习之镜像导入导出及推送阿里云服务器(三)
在前面两节里主要就是记录一些docker的基本的操作,包括搜索镜像,拉取镜像,根据镜像创建容器等等,在这一节主要就是记录Docker对于镜像文件的导入导出,及推送到阿里云再从阿里云获取镜像. 一.镜像 ...
- db.mybatis.config
config1: <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryB ...
- 洛谷 P2634 聪聪可可
题目描述 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一般情况下石头剪刀布就好了,可是他们已 ...
- php的排序算法
*对于算法来说,对于每个小伙伴来说都是比较头疼的,但是,为什么要学习算法? 算法是基础,算法能够提升智力,我想这两点就值得我们花时间去学习了.不要放弃,实在不会,先死记硬背下来,以后慢慢理解,一下是我 ...
- JAVA面试题0 JAVA语言的基本知识
JAVA语言的特点是什么? >面向对象:两个基本概念:类和对象:三大基本特性:封装.继承.多态: >健壮性:java吸收了C/C++的优点,但是去掉了它们影响健壮性的部分,例如指针和内存申 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- redis学习(四)
一.Redis 键(key) 1.Redis 键命令用于管理 redis 的键. 2.Redis 键命令的基本语法如下:redis 127.0.0.1:6379> COMMAND KEY_NAM ...