题目链接: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(模拟题)的更多相关文章

  1. Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列

    题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...

  2. ZOJ1111:Poker Hands(模拟题)

    A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...

  3. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  4. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  5. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  6. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  7. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  8. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  9. cdoj 25 点球大战(penalty) 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

随机推荐

  1. Oralce Exp 与 Imp 的使用方法

    1.完全:EXP  SYSTEM/SYSTEM@ORCL  FILE=C:\FULL.DMP  LOG=C:\FULL.DMP.LOG  FULL=Y  BUFFER=819200如果要执行完全导出, ...

  2. 锁·——lock关键字详解

    作  者:刘铁猛 日  期:2005-12-25 关键字:lock 多线程 同步 小序 锁者,lock关键字也.市面上的书虽然多,但仔细介绍这个keyword的书太少了.MSDN里有,但所给的代码非常 ...

  3. BZOJ 1415: [Noi2005]聪聪和可可( 最短路 + 期望dp )

    用最短路暴力搞出s(i, j)表示聪聪在i, 可可在j处时聪聪会走的路线. 然后就可以dp了, dp(i, j) = [ dp(s(s(i,j), j), j) + Σdp(s(s(i,j), j), ...

  4. Scala基础类型与操作

    Scala基本类型及操作.程序控制结构 Scala基本类型及操作.程序控制结构 (一)Scala语言优势 自身语言特点: 纯面向对象编程的语言 函数式编程语言 函数式编程语言语言应该支持以下特性: 高 ...

  5. 一个关于css3背景透明的例子

    大家都知道使用opacity调节透明度不仅是背景透明了而且选择区域的文字也跟着透明了, 这是我们不想要的效果,于是强大的css3便有了只让背景透明的功能 那就是background:rgba(0,0, ...

  6. SQL调优日志--内存问题

    SQL调优日志--内存问题排查入门篇   概述 很多系统的性能问题,是由内存导致的.内存不够会导致页面频繁换入换出,IO队列高,进而影响数据库整体性能. 排查 内存对数据库性能非常重要.那么我当出现问 ...

  7. JAVA泛型接口

    事例代码: package com.xt.thins_15_3; import java.util.Iterator; /** * 泛型接口 * * @author xue * * @param &l ...

  8. XmlDocument加载有Xmlns的xml文档,使用Xpath

    using System; using System.IO; using System.Xml; public class Sample { public static void Main() { X ...

  9. mysqldump 利用rr隔离实现一致性备份

    mysqldump -p -S /data/mysqldata1/sock/mysql.sock --single-transaction --master-data=2 --database db1 ...

  10. no protocol specified

    基于vncserver安装oracle or oracle RAC时 以root账号运行xhost + 在切换到grid or oracle安装oracle database file or clus ...