题目链接:http://poj.org/problem?id=3750

约瑟夫问题,直接模拟即可。

 #include <iostream>
#include <string>
using namespace std; const int maxn = ; int main()
{
char ch;
int i, n, w, s, num[maxn];
string per[maxn];
while (scanf("%d", &n) != EOF)
{
for (i = ; i < n; i++)
{
cin >> per[i]; // 保存人名
num[i] = i; // 保存人名所对应的编号
}
cin >> w >> ch >> s;
w = w - ; // 严谨写法应为:w = (w-1+n) % n,但题目说w < n,所以这样写也能通过,表示游戏刚开始时第一个报数人的编号,数组下标是从0开始的
do
{
// printf("n = %d\n", n);
w = (w + s - ) % n; // 得出从第w个开始的第s个位置,如果超出n,则mod n 来保证循环
cout << per[num[w]] << endl; // 该人出列
for (i = w; i < n-; i++)
per[i] = per[i+]; // 后面的人顶上出列的人的位置,即都往前挪
} while (--n); // 注意是--n,n--是错误的!!
}
return ;
}

poj 3750 小孩报数问题 解题报告的更多相关文章

  1. poj 3750 小孩报数问题

    小孩报数问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11527   Accepted: 5293 Descripti ...

  2. POJ 3750 小孩报数问题 (线性表思想 约瑟夫问题 数组模拟运算的 没用循环链表,控制好下标的指向就很容易了)

    小孩报数问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10423   Accepted: 4824 Descripti ...

  3. (顺序表应用5.1.1)POJ 3750 小孩报数问题(基本的约瑟夫环问题:给出人数n,出发位置w,间隔数s)

    /* * POJ_3750.cpp * * Created on: 2013年10月30日 * Author: Administrator */ #include <iostream> # ...

  4. POJ 2054 Color a Tree解题报告

    题干 Bob is very interested in the data structure of a tree. A tree is a directed graph in which a spe ...

  5. 【原创】POJ 1703 && RQNOJ 能量项链解题报告

    唉 不想说什么了 poj 1703,从看完题到写完第一个版本的代码,只有15分钟 然后一直从晚上八点WA到第二天早上 最后终于发现了BUG,题目要求的“Not sure yet.”,我打成了“No s ...

  6. poj 3617 Best Cow Line 解题报告

    题目链接:http://poj.org/problem?id=3617 题目意思:给出一条长度为n的字符串S,目标是要构造一条字典序尽量小,长度为n的字符串T.构造的规则是,如果S的头部的字母 < ...

  7. poj 2771 Guardian of Decency 解题报告

    题目链接:http://poj.org/problem?id=2771 题目意思:有一个保守的老师要带他的学生来一次短途旅行,但是他又害怕有些人会变成情侣关系,于是就想出了一个方法: 1.身高差距   ...

  8. poj 1274 The Perfect Stall 解题报告

    题目链接:http://poj.org/problem?id=1274 题目意思:有 n 头牛,m个stall,每头牛有它钟爱的一些stall,也就是几头牛有可能会钟爱同一个stall,问牛与 sta ...

  9. [poj 3349] Snowflake Snow Snowflakes 解题报告 (hash表)

    题目链接:http://poj.org/problem?id=3349 Description You may have heard that no two snowflakes are alike. ...

随机推荐

  1. 打印cell的视图层次结构

    #ifdef DEBUG NSLog(@"Cell recursive description:\n\n%@\n\n", [cell performSelector:@select ...

  2. getHibernateTemplate()的用法

    getHibernateTemplate() spring 中获得由spring所配置的hibernate的操作对象,然后利用此对象进行,保存,修改和删除等操作,此方法是在配置了spring以后,hi ...

  3. 【bzoj1502】 NOI2005—月下柠檬树

    http://www.lydsy.com/JudgeOnline/problem.php?id=1502 (题目链接) 今天考试题,从来没写过圆的面积之类的东西..GG 题意 一颗树由n个圆台组成,现 ...

  4. USACO 3.3 fence 欧拉回路

    题意:求给定图的欧拉回路(每条边只走一次) 若欧拉回路存在,图中只可能有0个or2个奇数度的点. 求解时,若有奇数度的点,则必须从该点开始.否则可以从任一点开始 求解过程:dfs //主程序部分 # ...

  5. HackerRank Ice Cream Parlor

    传送门 Ice Cream Parlor Authored by dheeraj on Mar 21 2013 Problem Statement Sunny and Johnny together ...

  6. Linux下SVN安装配置和使用中遇到的问题

    两个命令: svn info :显示版本库信息,svn的下载url等. svn co https://xxxxx/xxx   wodemulu   (通过我的目录制定co的文件夹) svn st:显示 ...

  7. Visual Studio Online Integrations-Sync and migration

      原文:http://www.visualstudio.com/zh-cn/explore/vso-integrations-directory-vs

  8. webexam项目杂记2

    strstr,stristr是返回匹配到的字符串,常规的字符串操作尽量避免使用正则, strstr是返回从匹配字符(串)开始(包括该匹配字符串)到结束的(或开头的)字符串 而如果仅仅只是判断是否包含匹 ...

  9. linux命令别名的使用

    语 法:alias[别名]=[指令名称] 1,查看该用户下的别名: alias 2,有的系统里没有ll这个命令,原因就是没有定义ll='ls -l --color=tty'这个别名 如果想永久生效,就 ...

  10. HDOJ 1907 John

    对于任意一个 Anti-SG 游戏,如果我们规定当局面中所有的单一游戏的 SG 值为 0 时,游戏结束,则先手必胜当且仅当:  (1)游戏的 SG 函数不为 0 且游戏中某个单一游戏的 SG 函数大于 ...