swjtu 2213 A Game About Cards(模拟题)
题目链接:http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=2213
思路分析:该问题与约瑟夫问题相似;每次将前n张牌放到队列的最后,可以将整个队列看做一个环,每次向前移动n步,则下一张牌的号码即被编号为n,
并在该环中除去该牌,在继续前行n+1步,如此循环,直到最后一张牌被编号。
代码如下:
#include <iostream>
using namespace std; const int MAX_N = ;
int del[MAX_N];
int num[MAX_N]; int main()
{
int times; cin >> times;
while (times--)
{
int n = ;
int index = -; memset(del, , sizeof(del));
memset(num, -, sizeof(num));
cin >> n;
for (int i = ; i < n; ++ i)
{
int times = i + ;
int go = times;
while (go)
{
index = (index + ) % n;
if (del[index] != )
go--;
}
index = (index + ) % n;
while (del[index] == )
index = (index + ) % n;
num[index] = times;
del[index] = ;
}
for (int i = ; i < n - ; ++i)
cout << num[i] << " ";
cout << num[n - ] << endl;
}
return ;
}
swjtu 2213 A Game About Cards(模拟题)的更多相关文章
- Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列
题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...
- ZOJ1111:Poker Hands(模拟题)
A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
- cdoj 25 点球大战(penalty) 模拟题
点球大战(penalty) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...
随机推荐
- UITextField键盘类型
UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)]; //初始化textfield并 ...
- c# Linq及Lamda表达式应用经验之 GroupBy 分组
示例1: GroupBy 分组在List<>泛型中的应用 原表: 按姓名Nam 分组后结果: 对DATATABLE 进行LAMDA查询时必须在项目的引用中添加 System.Data.Da ...
- no data type for node
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.IdentNode \-[IDE ...
- Java学习之String对象为什么是不可变的
转自:http://www.2cto.com/kf/201401/272974.html,感谢作者的总结 什么是不可变对象? 众所周知, 在Java中, String类是不可变的.那么到底什么是不可变 ...
- linux杂记(四)热键[Tab],[ctrl]-c,[ctrl]-d,在线求助man page/info page
[Tab]按键 他具有[命令补全](接在一串指令的第一个字后面)与[档案补齐](接在第一串指令的第二字以后时)的功能.如 [KANO@kelvin ~]$ ca[tab][tab] cabextrac ...
- 一个关于css3背景透明的例子
大家都知道使用opacity调节透明度不仅是背景透明了而且选择区域的文字也跟着透明了, 这是我们不想要的效果,于是强大的css3便有了只让背景透明的功能 那就是background:rgba(0,0, ...
- codeforces 650B . Image Preview 二分
题目链接 B. Image Preview time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Xcode GDB 命令list
此文下半部分为转载:但是这里有一些我自己使用技巧,结合下面的文章,我们会有更多的收获,在此感谢原创者. --------------------- 关于调试异常崩溃: 一般崩溃是由内存使用错误 ...
- html字符实体对照表
- windows中使用Git工具连接GitHub(配置篇)
Git在源码管理领域目前占很大的比重了,而且开源的项目很多都转到GitHub上面了.例如:jQuery, reddit, Sparkle, curl, Ruby on Rails, node.js, ...