poj3629 Card Stacking

74 篇文章 0 订阅
54 篇文章 0 订阅

题目链接:http://poj.org/problem?id=3629
题意:在桌子上有k张牌,牌面分别是1~k,然后有k/n张好牌,每次拿最开始那一张牌,判断是你拿的第几张排,如果刚好是张好牌就把这张牌那走,然后把开始这p张牌放在最后面,直至k/n张好牌全部拿完为止,让你升序输出这k/n张牌的牌面
解析:用队列直接模拟

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
using namespace std;
const int maxn = 1e5+100;
const int inf = 0x7ffffff;
int ans[maxn];
int main(void)
{
    int n,k,p;
    scanf("%d %d %d",&n,&k,&p);
    queue<int>q;
    for(int i=1;i<=k;i++)
        q.push(i);
    int cnt = 1,tt = 0;
    while(!q.empty())
    {
        if(cnt%n==0)
        {
            ans[tt++] = q.front();
            if(tt == n/k)
                break;
        }
        cnt++;
        q.pop();
        for(int j=0;j<p;j++)
        {
            int tmp = q.front();
            q.push(tmp);
            q.pop();
        }
    }
    sort(ans,ans+tt);
    for(int i=0;i<tt;i++)
        printf("%d\n",ans[i]);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值