题目链接: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 ;
}

最新文章

  1. C#限速下载网络文件
  2. Appirater -- app中提示用户为app评价的提示框
  3. Node.js——Async
  4. 适用于jquery1.11.1的ajaxfileupload.js
  5. HDU 3389 (Nim博弈变形) Game
  6. SQLServer 2008数据库查看死锁、堵塞的SQL语句
  7. &lt;Win32_9&gt;有意思的程序——抓取屏幕
  8. EXPDP和IMPDP简单测试
  9. 数学期望和概率DP题目泛做(为了对应AD的课件)
  10. spring学习总结(mybatis,事务,测试JUnit4,日志log4j&amp;slf4j,定时任务quartz&amp;spring-task,jetty,Restful-jersey等)
  11. Java 三目运算符表达式的一些问题
  12. 小巧玲珑:机器学习届快刀XGBoost的介绍和使用
  13. 树莓派安装 MySQL 时出现错误的解决方法
  14. 亿级SQL Server运维的最佳实践PPT分享
  15. 思科模拟器PacketTracer7--利用一台交换机和2台pc互连构成小型局域网
  16. processjs Documentation
  17. 第二周Access课总结
  18. 基于tensorflow搭建一个神经网络
  19. ALSA学习资料
  20. 内存对齐与ANSI C中struct型数据的内存布局 【转】

热门文章

  1. spring boot 中容器 Jetty、Tomcat、Undertow
  2. Shell Sort(希尔排序)
  3. [CMake笔记] 初识CMake
  4. redhat 7.6 安装 inotify-tools 文件监控工具 搭配rsync
  5. 8年经验面试官详解 Java 面试秘诀
  6. Lesson 9 Royal espionage
  7. mmap 与 munmap
  8. 使用anaconda 3安装tensorflow 1.15.0 (win10环境)
  9. ionic3记录之弹窗Alert
  10. HBase基准测试