博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Throwing cards away I
阅读量:7013 次
发布时间:2019-06-28

本文共 1565 字,大约阅读时间需要 5 分钟。

                                                                           Throwing cards away I 
  Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck:
  Throw away the top card and move the card that is now on the top of the deck to the bottom of the deck. 
Your task is to find the sequence of discarded cards and the last, remaining card. 
Input Each line of input (except the last) contains a number n ≤ 50. The last line contains ‘0’ and this line should not be processed. 
Output For each number from the input produce two lines of output. The first line presents the sequence of discarded cards, the second line reports the last remaining card. No line will have leading or trailing spaces. See the sample for the expected format. 
Sample Input 
7 19 10 6 0 
Sample Output
Discarded cards: 1, 3, 5, 7, 4, 2 
Remaining card: 6 
Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 4, 8, 12, 16, 2, 10, 18, 14 
Remaining card: 6 
Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8 
Remaining card: 4 
Discarded cards: 1, 3, 5, 2, 6 
Remaining card: 4
 
 
 
题目大意:
一副牌完全按顺序排好,然后你要做的就是每次扔掉最前面一张牌,再把此时最前的一张牌放到最后面去,最后输出你扔的那些牌和最后剩下的牌
 
 
思路:
典型的队列,用队列模拟就好。
 
代码:
 
 
#include"iostream"using namespace std; const int maxn=2600; int a[maxn]; int n; void Work() { for(int i=1;i<=n;i++) a[i]=i; int head=1; int tail=n; if(tail==1) cout<
<<"Remaining card: "<
<
>n&&n) { cout<<"Discarded cards:"; Work(); } return 0; }

 

转载于:https://www.cnblogs.com/zsyacm666666/p/4652588.html

你可能感兴趣的文章
Java是如何处理别名(aliasing)的
查看>>
ArcGIS API for javascript开发笔记(四)——GP服务调用之GP模型的规范化制作详解...
查看>>
halcon算子翻译——region_to_bin
查看>>
巨杉数据库助力民生银行、广发银行前台智慧化业务
查看>>
DOM
查看>>
http是什么?
查看>>
Linux上iptables防火墙的基本应用教程
查看>>
[LeetCode]Symmetric Tree
查看>>
[LeetCode]Missing Number
查看>>
树莓派 基础系列 | 软件源收集 更改
查看>>
[Swust OJ 403]--集合删数
查看>>
利用正则表达式分离汉字、英文、数字
查看>>
扩展 Entity Farmework 支持随机排序
查看>>
EF的BeginTransaction 用法
查看>>
MVC 4 中编译时,让View 也弹出异常
查看>>
项目管理的“三边六拍”!(转)
查看>>
Delphi XE5 for Android之Orientation的问题
查看>>
map() Filter() lambda函数说明
查看>>
Redis集群总结
查看>>
jssor/slider图片的问题
查看>>