#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int main()
{
int i,j,w,s,n;
char a[65][16];
int p[65];
scanf("%d",&n);
for(i=1;i<=n;i++)
{
p[i]=i;
scanf("%s",&a[i]);
} scanf("%d,%d",&w,&s);
w=(w+n)%n; while(n-1){ w=(w+s-1)%n;
printf("%s\n",a[p[w]]);
for(j=w;j<n;j++)
p[j]=p[j+1];
n--;
cout<<w<<" "<<n<<endl;
}
return 0;
}
//WA代码↑

POJ3750





题意:约瑟夫环问题。





输入:

n(人数)

str(人的姓名)

w(起始下标)s(间隔人数)





输出:

str(人的姓名)





思路:约瑟夫环问题,直接模拟起始w=(w+n-1)%n,出去下标w=(w+s-1)%n,在后面要把环的下标更新即可。





AC代码:

#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int main()
{
int i,j,w,s,n;
char a[65][16];
int p[65];
scanf("%d",&n);
for(i=0;i<n;i++)
{
p[i]=i;
scanf("%s",&a[i]);
} scanf("%d,%d",&w,&s);
w=(w+n-1)%n; while(n){ w=(w+s-1)%n;
printf("%s\n",a[p[w]]);
for(j=w;j<n-1;j++)
p[j]=p[j+1];
n--;
// cout<<w<<" "<<n<<endl;
}
return 0;
}

POJ3750的更多相关文章

  1. POJ3750: 小孩报数问题+一道经典约瑟夫问题(猴子选大王)

    又一次因为一个小错误,POJ上Wrong Answer了无数次..... 在差不多要放弃的时候,发现了这个猥琐的不能再猥琐的bug,改完了提交就AC了,简直无语.... 本题wo采用模拟方法: 1 # ...

  2. 约瑟夫问题 小孩报数问题poj3750

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

随机推荐

  1. JQUERY1.9学习笔记 之内容过滤器(三) has选择器

    描述:选择至少包含一个元素,匹配指定的标签的标签.jQuery( ":has(selector)" ) 例:给所有的div添加一个类"test",在他们中有一个 ...

  2. sql 语句左连接右连接小例子

    A表(a1,b1,c1) B表(a2,b2) a1 b1 c1 a2 b2 01 数学 95 01 张三 02 语文 90 02 李四 03 英语 80 04 王五 select A.*,B.* fr ...

  3. hdu3949

    XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. IOS--UIAlertView的使用方法详细

    IOS--UIAlertView的使用方法详细   // UIAlertView的常用方法 // 标准样式 UIAlertView *oneAlertView = [[UIAlertView allo ...

  5. 简单又强大的联发科手机PhilZ Touch Recovery安装器,详细教程 - 本文出自高州吧

    原文地址:http://bbs.gaozhouba.com/thread-19355-1-1.html * * * * * * * * * * * * * * * * * * * * * * * * ...

  6. Ansible二三事

    现在,慢慢测试一下ANSIBLE的功能,不过,总体感觉是,比SALTSTACK运行要慢,好像还有点点不稳定.... 但,在局域环境的表现,还是不错的... ~~~~~~~~~~~~~ 有几个小事要注意 ...

  7. Android调用 Webservice报org.ksoap2.serialization.SoapPrimitive(转)

    android Webservice开发的时候一般情况下大家接受webservice服务器返回值的时候都是使用SoapObject soapObject = (SoapObject) envelope ...

  8. BZOJ 1003 [ZJOI2006]物流运输trans

    1003: [ZJOI2006]物流运输trans Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4242  Solved: 1765[Submit] ...

  9. -_-#【Angular】自定义指令directive

    AngularJS学习笔记 <!DOCTYPE html> <html ng-app="Demo"> <head> <meta chars ...

  10. HDU 1045 Fire Net(图匹配)

    题目大意: 这个是以前做过的一道DFS题目,当时是完全暴力写的. 给你一个N代表是N*N的矩阵,矩阵内 ‘X’代表墙, ‘.’代表通道. 问这个矩阵内最多可以放几个碉堡, 碉堡不能在同一行或者同一列, ...