题目链接:https://ac.nowcoder.com/acm/contest/993/A
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.

输入描述:

* Line 1: Three space-separated integers: N, K, and P

输出描述:

* 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.
示例1

输入

复制

3 9 2

输出

复制

3
7
8

说明

Bessie should put the "good" cards in positions 3, 7, and 8. The cards will be dealt as follows; the card numbers are "position in original deck":
Card Deck P1 P2 Bessie
Initial configuration 1 2 3 4 5 6 7 8 9 - - - - - - - - -
Deal top card [1] to Player 1 2 3 4 5 6 7 8 9 1 - - - - - - - -
Top card to bottom (#1 of 2) 3 4 5 6 7 8 9 2 1 - - - - - - - -
Top card to bottom (#2 of 2) 4 5 6 7 8 9 2 3 1 - - - - - - - -
Deal top card [4] to Player 2 5 6 7 8 9 2 3 1 - - 4 - - - - -
Top card to bottom (#1 of 2) 6 7 8 9 2 3 5 1 - - 4 - - - - -
Top card to bottom (#2 of 2) 7 8 9 2 3 5 6 1 - - 4 - - - - -
Deal top card [7] to Bessie 8 9 2 3 5 6 1 - - 4 - - 7 - -
Top card to bottom (#1 of 2) 9 2 3 5 6 8 1 - - 4 - - 7 - -
Top card to bottom (#2 of 2) 2 3 5 6 8 9 1 - - 4 - - 7 - -
Deal top card [2] to Player 1 3 5 6 8 9 1 2 - 4 - - 7 - -
Top card to bottom (#1 of 2) 5 6 8 9 3 1 2 - 4 - - 7 - -
Top card to bottom (#2 of 2) 6 8 9 3 5 1 2 - 4 - - 7 - -
Deal top card [6] to Player 2 8 9 3 5 1 2 - 4 6 - 7 - -
Top card to bottom (#1 of 2) 9 3 5 8 1 2 - 4 6 - 7 - -
Top card to bottom (#2 of 2) 3 5 8 9 1 2 - 4 6 - 7 - -
Deal top card [3] to Bessie 5 8 9 1 2 - 4 6 - 7 3 -
Top card to bottom (#1 of 2) 8 9 5 1 2 - 4 6 - 7 3 -
Top card to bottom (#2 of 2) 9 5 8 1 2 - 4 6 - 7 3 -
Deal top card [9] to Player 1 5 8 1 2 9 4 6 - 7 3 -
Top card to bottom (#1 of 2) 8 5 1 2 9 4 6 - 7 3 -
Top card to bottom (#2 of 2) 5 8 1 2 9 4 6 - 7 3 -
Deal top card [5] to Player 2 8 1 2 9 4 6 5 7 3 -
Top card to bottom (#1 of 2) 8 1 2 9 4 6 5 7 3 -
Top card to bottom (#1 of 2) 8 1 2 9 4 6 5 7 3 -
Deal top card [8] to Bessie - 1 2 9 4 6 5 7 3 8
Bessie will end up with the "good cards" that have been placed in positions 3, 7, and 8 in the original deck. 题意:n 个人玩 k 张牌,发牌员是 n 号,一共有 k/n 张好牌,发牌员全都要,问需要把好牌放在哪里才能拿到。(发牌规则:从 1 号开始,每次发一张牌,发完之后把牌堆顶部的 p 张牌全部放到牌堆底部。然后继续发牌。) 队列:队列的入队规则,先进先出
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
vector<int>a[];
queue<int>q;
int main()
{
int n, k, p, cnt = ;
cin >> n >> k >> p;
for (int i = ; i <= k; i++)
q.push(i);
while (!q.empty())
{
int x;
x = q.front();
q.pop();
a[cnt].push_back(x);
for (int i = ; i < p&&!q.empty(); i++)//注意要判空,否则会段错误
{
int temp;
temp = q.front();
q.pop();
q.push(temp);
}
cnt++;
if (cnt > n)
cnt=;
}
sort(a[n].begin(), a[n].end()); for (int i = ; i < a[n].size(); i++)
cout << a[n][i] << endl; return ;
}

Card Stacking 队列模拟的更多相关文章

  1. Codeforces 704A Thor 队列模拟

    题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...

  2. python--递归(附利用栈和队列模拟递归)

    博客地址:http://www.cnblogs.com/yudanqu/ 一.递归 递归调用:一个函数,调用的自身,称为递归调用 递归函数:一个可以调用自身的函数称为递归函数 凡是循环能干的事,递归都 ...

  3. PTA 银行排队问题之单队列多窗口加VIP服务 队列+模拟

    假设银行有K个窗口提供服务,窗口前设一条黄线,所有顾客按到达时间在黄线后排成一条长龙.当有窗口空闲时,下一位顾客即去该窗口处理事务.当有多个窗口可选择时,假设顾客总是选择编号最小的窗口. 有些银行会给 ...

  4. 原生JS实现队结构及利用队列模拟‘击鼓传花’游戏

    1. 前言 队列,是一种遵从先进先出(FIFO,First-In-First-Out)原则的有序集合.队列在尾部添加新元素,并从顶部移除元素,最新添加的元素必须排在队列的末尾. 2.功能说明 enqu ...

  5. 两队列模拟一个栈,python实现

    python实现两个队列模拟一个栈: class Queue(object): def __init__(self): self.stack1=[] self.stack2=[] def enqueu ...

  6. hdu-5929 Basic Data Structure(双端队列+模拟)

    题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  7. uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列

    题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间. 这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数 ...

  8. [Swust OJ 352]--合并果子(贪心+队列模拟)

    题目链接:http://acm.swust.edu.cn/problem/352/ Time limit(ms): 1000 Memory limit(kb): 65535   Description ...

  9. [POJ2259]Team Queue (队列,模拟)

    2559是栈,2259是队列,真的是巧啊 题意 模拟队列 思路 水题 代码 因为太水,不想打,发博客只是为了与2559照应,于是附上lyd的std #include <queue> #in ...

随机推荐

  1. 【剑指Offer面试编程题】 题目1350:二叉树的深度--九度OJ

    题目描述: 输入一棵二叉树,求该树的深度.从根结点到叶结点依次经过的结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. 输入: 第一行输入有n,n表示结点数,结点号从1到n.根结点为1. ...

  2. Codeforces Round #580 (Div. 2)D(思维,Floyd暴力最小环)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;const int maxn=300;cons ...

  3. 奈奎斯特采样定理(Nyquist)

    采样定理在1928年由美国电信工程师H.奈奎斯特首先提出来的,因此称为奈奎斯特采样定理. 1933年由苏联工程师科捷利尼科夫首次用公式严格地表述这一定理,因此在苏联文献中称为科捷利尼科夫采样定理. 1 ...

  4. Codeforces1303E. Erase Subsequences

    转换一下题意,就相当于问t能不能和s中2个不相同的子串相同,我们可以将t串拆成2个子串t1,t2,得到状态dp[i][j][k]=0/1,表示s判断到i位,t1判断到j位,t2判断到k位,0/1表示是 ...

  5. C++11并发编程2------线程管理

    本节内容: 启动一个线程 每个程序都至少会有一个线程,main函数是执行入口,我们称之为主线程,其余子线程有各自的入口函数,主线程和子线程同时运行.子线程在std::thread对象创建时启动. 1. ...

  6. siblings() 获取同胞元素的用法

    1. $("h2").siblings().css({"color":"red","border":"2px ...

  7. 「NOWCODER」CSP-S模拟赛第3场

    「NOWCODER」CSP模拟赛第3场 T1 货物收集 题目 考场思路即正解 T2 货物分组 题目 考场思路 题解 60pts 算法:一维 DP 100pts 算法:一维 DP ?线段树 + 单调栈 ...

  8. 视图家族 & 路由组件

    目录 视图家族 & 路由组件 视图集与路由组件 基于 GenericAPIView 的十大接口 基于 generics 包下工具视图类的六大基础接口 视图集 路由组件:必须配合视图集使用 自定 ...

  9. python 开启http服务并下载文件

    Python <= 2.3python -c "import SimpleHTTPServer as s; s.test();" 8000 Python >= 2.4p ...

  10. 被动信息收集-其他收集目标信息的途径:cupp、 recon-ng

    除了google等搜索收集,还有其他途径进行信息收集,其中就包括用命令行或集成的软件.框架进行搜集信息. 1.先举例几个简单的命令: 其实也会是调用搜索引擎,如谷歌必应等,需要翻墙,可以用proxyc ...