A - Card Stacking

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status

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: NK, 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
 一个模拟题,我想了一下就决定用队列来模拟发牌过程,事实证明也很顺利,只是不知为何,OJ会说我runtime error,我把数组什么的都尽量开大了,还是没办法,难道队列还能爆?这根据题目的数据,不可能啊。。后来我搜了一下博客,也有跟我思路完全一样的人,但是人家用JAVA写的,就过了。我就很奇怪,不过我自认为我的程序应该是没有问题了。
 
过了两天,因为正好又碰到一个runtime error的题目,这次我找到我代码的BUG是发现有个地方会引起无限循环从而使数组爆掉,改好后就AC了,我再想起这个题目,于是今晚回过头来改一下,发现只要在队列中,判断依据 if(sum>=k/n) break;,也就是说,只要找到了题目要求的k/n个最好牌,就直接退出队列模拟。。。然后再提交,就AC了。。于是乎,我终于找到出问题的地方了,就是在模拟里面,每次while(!q.empty())循环里面出现了超过2次q.pop(),也就是说模拟到最后的牌,其实q队列已经空了,但是还是会继续访问下去,这样就是问题所在,果不其然,我拿之前错的代码,改了一个新的地方,在循环体里面还判断一下队列是否为空。。果不其然就A掉了
 
之前还在骂这个题目,为这个一个小BUG弄的时间比写代码的时间还长。。还是不够老练啊。。本来 if(sum>=k/n) break;这种代码明显可以优化时间(AC了几次发现这句话确实为我节省了几十ms) 我在第一次写的时候就应该写上的。。还至于到了最后不仅没有任何优化,还因为这样的小细节弄出自己半天都想不出来的bug。谨以为记。
  
 
顺便吐槽一下,POJ上没说是多组数据的样子啊。。怎么要用到while(scanf()!=EOF)?
代码自认为用队列用得挺好。
 
#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 模拟的更多相关文章

  1. POJ 3629 队列模拟

    听说STL会卡T 然后我就试了一发 哈哈哈哈哈哈哈哈哈哈 1000ms卡时过的 这很值得我写一发题解了 哈哈哈哈哈哈哈哈哈哈哈哈 //By SiriusRen #include <queue&g ...

  2. POJ 1016 模拟字符串

    Numbers That Count Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20396   Accepted: 68 ...

  3. POJ 1208 模拟

    2017-08-28 15:07:16 writer:pprp 好开心,这道题本来在集训的时候做了很长很长时间,但是还是没有做出来,但是这次的话,只花了两个小时就做出来了 好开心,这次采用的是仔细分析 ...

  4. POJ - 3087 模拟 [kuangbin带你飞]专题一

    模拟洗牌的过程,合并两堆拍的方式:使先取s2,再取s1:分离成两堆的方式:下面C张放到s1,上面C张到s2.当前牌型与第一次相同时,说明不能搜索到答案. AC代码 #include<cstdio ...

  5. Shuffle'm Up POJ - 3087(模拟)

    Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15249   Accepted: 6962 Des ...

  6. poj 1379 模拟退火法

    /* 模拟退火法: 找到一些随机点,从这些点出发,随机的方向坐标向外搜索: 最后找到这些随机点的最大值: 坑://if(xx>-eps&&xx<x+eps&& ...

  7. POJ 1471 模拟?

    题意:求最大无坏点三角形 思路: 模拟? (为什么我模拟过了...) 有人用 DP,有人用 搜索... // by SiriusRen #include <cstdio> #include ...

  8. POJ 1951 模拟

    思路: 坑爹模拟毁我一生 给两组数据: 输入: YOURE TRAVELING THROUGH ANOTHER DIMENSION A DIMENSION NOT OF SIGHT. 输出: YR T ...

  9. POJ 2141 模拟

    思路:字符串解密 啥都告诉你了 模拟就好 //By SiriusRen #include <cstdio> #include <cstring> using namespace ...

  10. POJ 2459 模拟

    题意: 思路: 按照题意模拟即可 //By SiriusRen #include <cstdio> using namespace std; int c,f1,f2,d,xx,yy,vis ...

随机推荐

  1. winodws系统搭建git服务--Tomcat--jdk配置

    一.http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html  下载jdk程序: 1.下载 ...

  2. RVA到FOA的转换

    地址空间:这个地址空间指的是PE文件被加载到内存的空间,是一个虚拟的地址空间,之所以不是物理空间是因为数据在内存中的位置经常在变,这样既可以节约内存开支又可以避开错误的内存位置.这个地址空间的大小为4 ...

  3. Readiness 探测【转】

    除了 Liveness 探测,Kubernetes Health Check 机制还包括 Readiness 探测. 用户通过 Liveness 探测可以告诉 Kubernetes 什么时候通过重启容 ...

  4. Kubernetes Dashboard 【转】

    前面章节 Kubernetes 所有的操作我们都是通过命令行工具 kubectl 完成的.为了提供更丰富的用户体验,Kubernetes 还开发了一个基于 Web 的 Dashboard,用户可以用 ...

  5. vue - 动态绑定 class

    <template>   <div class="todo-item" :class="{'is-complete':todo.completed}&q ...

  6. Oracle修改密码

    1. 登陆oracle sqlplus '/as sysdba' 2. 修改密码 ALTER USER 用户名IDENTIFIED BY 要修改的密码 ; 3.解锁 alter user 用户名 ac ...

  7. docker-compose(grafana influxdb) + telegraf 快速搭建简单监控

     灵活实现方案:   1:     telegraf 为go 语言写得占用内存小 收集主机各项监控数据 定时写入 时序DB   influxdb ------------------------&qu ...

  8. Arch系linux配置Go开发环境

    1. 下载go $ sudo pacman -S go 下载后系统会将go安装在/usr/lib/go目录下 2. 配置一些环境变量 一共需要三个环境变量,分别为: GOROOT -> go语言 ...

  9. msf自动连接postgresql配置

    今天做了一下msf连接数据库的配置,中间碰到了一些坑点这里就不详细叙述了,开始正确的操作方式. 首先对postgresql进行配置以方便连接. root@kali:~# service postgre ...

  10. 使用 Dashboard【转】

    上一节我们完成了 Kubernetes Dashboard 的安装,本节就来实践一下. Dashboard 界面结构 Dashboard 的界面很简洁,分为三个大的区域. 顶部操作区在这里用户可以搜索 ...