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 ...
随机推荐
- java 获取本机ip及mac地址
package com.achun.test; import java.net.Inet4Address;import java.net.Inet6Address;import java.net.In ...
- qt检测网络连接状态【只能检测和路由器的连接,不能测试到外网的连接】
#include <QCoreApplication>#include <QDebug>#include <QTextStream>#include <QDi ...
- Mybatis使用存储过程(MySql)
推荐文章:http://www.iteye.com/topic/1132302 http://yhjhappy234.blog.163.com/blog/static/3163283220124557 ...
- 本地搭建php环境
AppServ 是 PHP 网页架站工具组合包,所包含的软件有:Apache[.Apache Monitor.PHP.MySQL.phpMyAdmin等,如果您的本地机器没有安装过php.mysql等 ...
- FZU Problem 1686 神龙的难题 重复覆盖
题目链接 给出大矩形的长宽, 矩形里面有1,0两个值, 给出小矩形的长宽, 求用最少的小矩形覆盖所有的1. 重复覆盖的模板题. #include <iostream> #include & ...
- java反编译命令javap
1. 输出所有类和成员 javap -private XX.class 2. 输出分解后的代码 javap -c XX.class
- 服务器响应HTTP请求状态码(转)
当服务器响应HTTP请求时,其状态行的信息为HTTP的版本号,状态码,及解释状态码的简单说明: 1.客户方错误: 100 客户必须继续发出请求 101 客户要求服务器根据请求转换HTTP协议版本 2. ...
- jquery.validate 一些技巧
1.Validator.element() Validates a single element, returns true if it is valid, false otherwise. http ...
- Android Memory/Resource Leak总结
Android的内存/资源泄露,不容易发现,又会引发app甚至是system的一系列问题. 在这里我根据以往碰到的相关问题,总结出了一些检测和修改方法. *有可能造成memory leak的代码是Fr ...
- SQL Server 数据岸问题
create table t2(x int constraint pk_t2 primary key);go insert into t2(x) values(1),(2),(3),(5),(7),( ...