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: 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

题意:

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的更多相关文章

  1. POJ 3629 队列模拟

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

  2. CSU训练分类

    √√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...

  3. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  4. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  5. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  6. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  7. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  8. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  9. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  10. 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 ...

随机推荐

  1. C# HTTP请求后对gzip页面实现解压缩

    1.通过socket页面请求后的receive内容不能经过string后再进行解压缩处理 会造成错误的gzip幻数报错 推荐使用流处理 2.正确分析返回内容 分割header和页面代码部分 3.对页面 ...

  2. 轻松搞定RabbitMQ(五)——路由选择

    转自 http://blog.csdn.net/xiaoxian8023/article/details/48733249 翻译地址:http://www.rabbitmq.com/tutorials ...

  3. ScrollView滑动的监听

    ScrollView滑动的监听 有时候我们须要监听ScrollView的滑动事件.来完毕业务需求. 第一种: 能够直接实现OnTouchListener接口.在这里面写你所须要的操作 scrollVi ...

  4. Ubuntu Server 12.04 乱码

    sudo vim /etc/default/locale 将 下面的内容修改 LANG="zh_CN.UTF-8" LANGUAGE="zh_CN:zh" 修改 ...

  5. JAVA sql语句动态参数问题

    对sql语句设置动态参数 import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverMan ...

  6. Package template (html/template) ... Types HTML, JS, URL, and others from content.go can carry safe content that is exempted from escaping. ... (*Template) Funcs ..

    https://godoc.org/text/template GoDoc Home About Go: text/templateIndex | Examples | Files | Directo ...

  7. Page (computer memory)

    A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described ...

  8. Java服务器端 API 错误码设计总结

    1.对于API结果返回,定义BaseResult 类 拥有success,errorCode,errorMsg个3个基本参数,success使用Boolean类型,errorCode使用Integer ...

  9. appium(11)-java-client

    Welcome to the Appium Java client wiki! This framework is an extension of the Selenium Java client. ...

  10. DNS常见攻击与防范

    DNS常见攻击与防范 转自:http://www.williamlong.info/archives/3813.html 日期:2015-7-10 随着网络的逐步普及,网络安全已成为INTERNET路 ...