POJ 3629 Card Stacking

Card Stacking

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
题目大意:有N只牛和K张卡牌,卡牌中有K / N张好牌和K - K / N张坏牌,其中一只牛bessie想得到所有的好牌,它的牛同伴为了防止biesse作弊,制定了以下发牌规则

(1)从bessie右手边开始发牌,每个人一张

(2)每次bessie发完牌之后都要将牌堆顶部的P张牌放到牌底

(3)按逆时针顺序重复这个过程,直到将牌发完

bessie非常想赢,它向你求助,应该把好牌放到哪些位置才能拿到所有好牌。

解题思路:使用队列模拟发牌过程,开一个数组存储bessie得到的牌的序号,排序输出即可。不得不说STL真是个好东西啊。。。

代码如下:

#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

int bessie[50005];

int main()
{
	int n,k,p,m;
	int good,bad;
	int i,j,l;
	while(scanf("%d %d %d",&n,&k,&p) != EOF){
		queue<int> que;
		for(i = 1;i <= k;i++)
			que.push(i);
		j = 1,l = 0;
		while(que.size()){
			if(j % n == 0){
				bessie[l] = que.front();
				l++;
			}
			que.pop();	
			for(i = 0;i < p;i++){
				que.push(que.front());
				que.pop();
			}
			j++;
		}
		sort(bessie,bessie + l);
		for(i = 0;i < l;i++)
			printf("%d\n",bessie[i]);
	}
	return 0;
} 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值