题目链接: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. 【UVA 1583】Digit Generator

    题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...

  2. 【CodeForces 618C】Constellation

    题 Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars n ...

  3. python:open文件操作

    file: jim|123|1 tom|321|3 kamil|432|1 # __author__ = liukun # coding:utf-8 obj = open('file.txt','r' ...

  4. 【bzoj1016】 JSOI2008—最小生成树计数

    http://www.lydsy.com/JudgeOnline/problem.php?id=1016 (题目链接) 题意 求图的最小生成树计数. Solution %了下题解,发现要写矩阵树,15 ...

  5. POJ3233 Matrix Power Series

    Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak. ...

  6. 5种风格的 jQuery 分页效果【附代码】

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  7. UVA11400照明系统设计&& POJ1260Peals(DP)

    紫书P275: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/A POJ http://poj.org/pr ...

  8. Spring学习8-SSH+Log4j黄金整合

    最下面有log4j的详解及配置步骤 步骤一.导入相应的jar包(具体参看下一篇博文) 步骤二.修改WEB.XML文件,内容如下: <?xml version="1.0" en ...

  9. jdbc链接mysql转

    完整java开发中JDBC连接数据库代码和步骤   JDBC连接数据库 •创建一个以JDBC连接数据库的程序,包含7个步骤: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的 ...

  10. 浏览器的中的 XMLHttpRequest 对象的使用

    使用XMLHttpRequest浏览器对象(IE5.IE6中是ActiveXObject对象)可以实现异步请求,Ajax就是以此为基础进行的封装. 1.同步与异步: <script type=& ...