| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
贴题意及代码/* 题意:
Bessie跟朋友玩牌,总共n人k张牌,k是n的整数倍。k张牌中共有k/n张好牌,Bessie想要作弊得到所有好牌。
可Bessie的同伴为了防止Bessie作弊而设定了如下规则:
1.每次发牌从牌顶发,从Bessie右手边第一个人开始。
2.每发出一张牌就要将接下来的p张牌依次放至牌底。
按照这个方法发完所有牌。即使是这样,Bessie依然想要拿到所有好牌,请你帮她计算出将好牌放在哪些位置可以实现Bessie的愿望。
*/
// 有 N 个人, 主角最后发牌,每发一次牌就从牌顶移动 P 张牌到牌尾
// 记录发给主角的牌的位置,因为主角要的是好牌,记录的位置即为好牌
// 好牌全部发完或者全部牌发完就结束游戏,目的是贝西拿到全部好牌即可
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#define Max 50005
using namespace std;
queue<int> l;
int N, K, P, n[Max], o = -1;
void create() {
while(!l.empty()) //清空队列
l.pop();
for(int i = 1; i<= K; i++) //依次存入
l.push(i);
}
void solve() {
int good = 0;
while( !l.empty() ) { //队内非空则取牌
int i = N;
while(i--) {
if(i == 0) { //轮到主人公取牌
n[++o] = l.front(); //存入好牌位置
l.pop();
good++;
if(good == K/N //若好牌已经取完则退出
return;
}
else
l.pop();
int b = P; //每发一张牌则移动牌顶 P
while(b--) { //张牌到牌尾,即先出队再入队
int c = l.front();
l.pop();
l.push(c);
}
}
}
}
void show() { //快排后再打印结果
sort(n, n+o+1);
for(int i = 0; i<= o; i++)
printf("%d\n", n[i]);
}
int main() {
scanf("%d %d %d", &N, &K, &P);
create();
solve();
show();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator