Card Stacking 队列模拟
题目链接: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.
说明
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 队列模拟的更多相关文章
- Codeforces 704A Thor 队列模拟
题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...
- python--递归(附利用栈和队列模拟递归)
博客地址:http://www.cnblogs.com/yudanqu/ 一.递归 递归调用:一个函数,调用的自身,称为递归调用 递归函数:一个可以调用自身的函数称为递归函数 凡是循环能干的事,递归都 ...
- PTA 银行排队问题之单队列多窗口加VIP服务 队列+模拟
假设银行有K个窗口提供服务,窗口前设一条黄线,所有顾客按到达时间在黄线后排成一条长龙.当有窗口空闲时,下一位顾客即去该窗口处理事务.当有多个窗口可选择时,假设顾客总是选择编号最小的窗口. 有些银行会给 ...
- 原生JS实现队结构及利用队列模拟‘击鼓传花’游戏
1. 前言 队列,是一种遵从先进先出(FIFO,First-In-First-Out)原则的有序集合.队列在尾部添加新元素,并从顶部移除元素,最新添加的元素必须排在队列的末尾. 2.功能说明 enqu ...
- 两队列模拟一个栈,python实现
python实现两个队列模拟一个栈: class Queue(object): def __init__(self): self.stack1=[] self.stack2=[] def enqueu ...
- hdu-5929 Basic Data Structure(双端队列+模拟)
题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列
题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间. 这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数 ...
- [Swust OJ 352]--合并果子(贪心+队列模拟)
题目链接:http://acm.swust.edu.cn/problem/352/ Time limit(ms): 1000 Memory limit(kb): 65535 Description ...
- [POJ2259]Team Queue (队列,模拟)
2559是栈,2259是队列,真的是巧啊 题意 模拟队列 思路 水题 代码 因为太水,不想打,发博客只是为了与2559照应,于是附上lyd的std #include <queue> #in ...
随机推荐
- Python基础-1 基础语法
基础语法 标识符 所谓的标识符就是对变量.常量.函数.类等对象起的名字. 首先必须说明的是,Python语言在任何场景都严格区分大小写!也就是说A和a代表的意义完全不同 python对于表示标识符的命 ...
- 夯实Java基础系列目录
自进入大学以来,学习的编程语言从最初的C语言.C++,到后来的Java,. NET.而在学习编程语言的同时也逐渐决定了以后自己要学习的是哪一门语言(Java).到现在为止,学习Java语言也有很长一段 ...
- 02-10Android学习进度报告十
今天我学习了有关ListView的基础知识,主要是学习了其中界面展示的基本方法. 首先看一个简单的列表实现代码: public class Animal { private String aName; ...
- Java Reflection (JAVA反射) --转载
对于软件开发人员来说,单元测试是一项必不可少的工作.它既可以验证程序的有效性,又可以在程序出现 BUG 的时候,帮助开发人员快速的定位问题所在.但是,在写单元测试的过程中,开发人员经常要访问类的一些非 ...
- 【html&css学习】表单及表单项
表单在网络中很常见,如百度的搜索框,各种登录框密码,贴吧的帖子等都需要用表单来完成.表单是元素form且必须要有action属性来设置表单提交的地址.使用form创建的仅仅只是空表单,还有要表单项,常 ...
- linux系统登陆过程
一.物理直连登陆过程 初始化进程init 会根据直接连接的字符终端设备,打开getty程序,并关联在字符终端设备上tty1/2/3/4/5/6/7....上,在不同的终端设备上提示用户输入信息,等待终 ...
- 三星 S10 运行 Ubuntu 系统
导读 DeX 是一种模仿桌面操作系统的用户 UI 界面,把支持 DeX 的三星手机用数据线连上外置显示器,用户就可以获得一种类似桌面系统的使用体验. 三星 S8.Note 8.S9.Note 9.S1 ...
- 新闻网大数据实时分析可视化系统项目——6、HBase分布式集群部署与设计
HBase是一个高可靠.高性能.面向列.可伸缩的分布式存储系统,利用Hbase技术可在廉价PC Server上搭建 大规模结构化存储集群. HBase 是Google Bigtable 的开源实现,与 ...
- 「牛客CSP-S2019赛前集训营2」服务器需求
传送门 NowCoder 解题思路 考虑一种贪心选择方法:每次选出最大的 \(m\) 个 \(a_i\) 进行覆盖. 那么就会出现一种特殊情况,最高的那个 \(a_i\) 需要多次选择,而且不得不每次 ...
- DDD-领域驱动设计之领域模型
DDD领域驱动设计基本理论知识总结 Posted on 2011-10-10 01:01 netfocus 阅读(120434) 评论(82) 编辑 收藏 领域驱动设计之领域模型 加一个导航,关于如何 ...