鄙人不才,此中鄙陋甚多,望海涵!!!

这里我们来详细讲解一下圆桌问题的相关题目

第一道一定是hdu的4841了,罪恶的源头

圆桌上围坐着2n个人。其中n个人是好人,另外n个人是坏人。如果从第一个人开始数数,数到第m个人,则立即处死该人;然后从被处死的人之后开始数数,再将数到的第m个人处死……依此方法不断处死围坐在圆桌上的人。试问预先应如何安排这些好人与坏人的座位,能使得在处死n个人之后,圆桌上围坐的剩余的n个人全是好人。

输入:多组数据,每组数据输入:好人和坏人的人数n(<=32767)、步长m(<=32767);

输出:对于每一组数据,输出2n个大写字母,‘G’表示好人,‘B’表示坏人,50个字母为一行,不允许出现空白字符。相邻数据间留有一空行。

输入

2 3

2 4

输出

GBBG

BGGB

C++代码

#include

#include

using namespace std;

vector res;

int main()

{

int n,m;

while(cin>>n>>m)

{

res.clear();//用res来模拟圆桌

for(int i=0;i<2*n;i++) res.push_back(i);//先将这2n个人放入res中;

int p=0;

for(int i=0;i

{

p=(p+m-1)%res.size();//每次先定位该死的坏人的位置,注意res下标从0开始,而且

//涉及到取余问题,记得减一

res.erase(res.begin()+p);//将坏人抹杀

}

for(int i=0,cnt=0;i<2*n;i++)

{

if(i%50==0 && i) puts("");//每50行输出一个换行

if(cnt

{//别忘了cnt

printf("G");

cnt++;

}

else printf("B");

}

cout<

}

return 0;

}

圆桌问题的简单应用

题目

“Eeny meeny miny moe” is a well-known nursery rhyme inEnglish, used (among other things) by kids to “randomly”select members of a team. It exists in many variations, oneof which goes like this:

Eeny, meeny, miny, moe,

Catch a tiger by the toe.

If he hollers, let him go,

Eeny, meeny, miny, moe.

Similar verses exist in most languages, such as “Ulle dulle dof” in Finnish, “Akka bakka bonka rakka” in Norwegian, and “Ole dole doff” in Swedish.

Two teams are to be selected for a game and the rhyme is used to select one kid for a team at a time, alternating between the two teams, until all kids have been selected. The kids are standing in a circle. In each selection round we start counting the kids in clockwise order around the circle, skipping one kid for every word in the rhyme, until the last word. The kid matching the last word is chosen for the current team and then the next round starts. In all rounds but the first, the counting starts at the next remaining kid (in clockwise order) after the one that was selected in the previous round.

Given such a rhyme, and a group of kids, can you tell which kids will be in which team?

Illustration of the first three rounds of Sample Input 1. In rounds 1 and 3, Alvar and Rakel get selected for the first team, and in round 2, Lisa is selected for the second team. In round 4 (not shown), only Kalle remains and is selected for the second team.

Input

The first line of input contains the rhyme, consisting of a list of words separated by spaces. The second line of input contains an integer n (1 ≤ n ≤ 100), the number of kids. Then follow the names of the kids, one per line. The kids are given in clockwise order and the first kid listed is the one at which counting starts in the first round.

All words and names consist only of upper and lower case letters ‘A’-‘Z’ and ‘a’-‘z’. No input line is empty or longer than 100 characters (excluding the newline character at the end of the line).

Output

Output the two teams, starting with the one whose first member is chosen first. For each team, output the number of kids in the team, followed by the names of the kids in the team, in the same order as they were chosen for the team.

样例1输入

eeny meeny miny

4

Kalle

Lisa

Alvar Rakel

样例1输出

2

Alvar

Rakel

2

Lisa

Kalle

样例2输入

Every Other

3

a

b

c

样例2输出

2

b

c

1

a

C++code

#include

#include

using namespace std;

vector a;

vector b;

vector sum;

string s;

int main()

{

int cnt=0,n=0;

while(cin>>s)

{

if(s[0]>='a' && s[0]<='z' || s[0]>='A' && s[0]<='Z') cnt++;

else

{

for(int i=0;i

break;

}

}

for(int i=0;i

{

string item;

cin>>item;

sum.push_back(item);

}

int m=1;

while(sum.size())

{

int pos=(pos+cnt-1)%sum.size();

if(m&1)

{

a.push_back(sum[pos]);

sum.erase(sum.begin()+pos);

}

else

{

b.push_back(sum[pos]);

sum.erase(sum.begin()+pos);

}

m++;

}

cout<< a.size() <

for(auto x:a) cout<< x <

cout<< b.size() <

for(auto x:b) cout<< x <

return 0;

}

总算是回到了游戏这题,这题其实就是属于圆桌问题的变种,关键就在于把报数的过程转化为每隔几个人就会被淘汰的问题,这就相当于n个人只有一个是好人,从第一个人开始每隔几个人就会抹杀一个坏人,最终剩下一个好人胜出

关键:处理这个隔几个人的问题

题目请到ccf官网自提

C++ Code

#include

#include

using namespace std;

vector res;//用res来模拟圆桌

int main()

{

int n,k;

cin>>n>>k;

for(int i=1;i<=n;i++) res.push_back(i);

for(int i=0,cnt=1,m=0;i

{

if(cnt%k==0 || cnt%10==k)

{

int p=(p+m)%res.size();

res.erase(res.begin()+p);

m=0,i++;//将m归0,并且淘汰人数加1

}

else m++;//这里m就是距离上一次淘汰所间隔人数

cnt++;//cnt表示所报的数

}

cout<< res[0] <

return 0;

}

持续更新中。。。。

ccf报数游戏java_ccf 201712 02 (游戏)相关推荐

  1. ccf报数游戏java_报数

    寒假作业22~242021-02-22 16:57:05 韩信点兵:在中国数学史上,广泛流传着一个"韩信点兵"的故事:韩信是汉高祖刘邦手下的大将,他英勇善战,智谋超群,为汉朝建立了 ...

  2. Unity3D游戏制作学习记录02——丛林战争

    Unity3D游戏制作学习记录02--丛林战争 Siki学院的视频教程指路牌:http://www.sikiedu.com/course/61. 一.服务器端--消息接收的异步处理 由于之前使用Rec ...

  3. [Game Framework之StarForce解读]02.游戏入口

    本文 Game Framework 版本:3.1.0 本文 Unity3D 版本:2017.3 更多GF教程和实例:https://github.com/mutouzdl/gameframework_ ...

  4. Unity 2D游戏开发教程之游戏中精灵的跳跃状态

    Unity 2D游戏开发教程之游戏中精灵的跳跃状态 精灵的跳跃状态 为了让游戏中的精灵有更大的活动范围,上一节为游戏场景添加了多个地面,于是精灵可以从高的地面移动到低的地面处,如图2-14所示.但是却 ...

  5. 游戏类型区分(做游戏的朋友可以看看)

    ACT......(ACTION GAME )动作游戏 STG......(SHOTING GAME )射击游戏 RPG......(ROLE PLAYING GAME )角色扮演游戏 A.RPG.. ...

  6. xposed新版52下载_kyqp游戏合集-kyqp游戏下载推荐

    下载 经营养成|0KB 更新时间:2020-10-23 17:28:05 评分: 概要:玩偶之城是一款最新最激情的欧美SLG新作.并且这里的角色都是童颜哦,非常带劲,并且游戏中的角色建模都是非常精美的 ...

  7. html微信小游戏,白鹭HTML5游戏转微信小游戏问题集锦,你关心的都在这里

    原标题:白鹭HTML5游戏转微信小游戏问题集锦,你关心的都在这里 首先,再次强调一些微信小游戏的基础技术限制: * 不允许操作 DOM.BOM.如果必须改成小游戏相应的 API 调用方式,目前引擎会自 ...

  8. Threejs系列--10游戏开发--沙漠赛车游戏【基础事件处理器】

    Threejs系列--9游戏开发--沙漠赛车游戏[基础事件处理器] 序言 目录结构 代码一览 Time.js代码 EventEmitter.js代码 Sizes.js代码 Application.js ...

  9. c语言反应能力的手机游戏,锻炼反应能力的游戏合集

    游戏大小:40.02 MB 拯救人民游戏是十款超级有趣的休闲类游戏,关卡的模拟为玩家提供,玩法非常的简单,但是还是有一点益智的玩法在里面,对于玩家来说都是一种非常不错的挑战,考验玩家个人的能力,越到后 ...

最新文章

  1. c++标准库获取随机数
  2. 京东数科宣布机房巡检AI机器人落地金融机构数据中心
  3. pandas如何统计所有列的空值,并转化为list?
  4. 用pandas填充时间序列缺失值
  5. java ee jsp_EE JSP:Servlet的反向外套
  6. HDU 5842—— Lweb and String CCPC 网络赛 1011
  7. win7如何设置还原点
  8. Spring源码分析-循环依赖
  9. 总结一些Android好用的开源库
  10. 企业安全监控zabbix安装部署方案—二进制安装
  11. toshiba linux 打印机驱动的资料
  12. 7-14 然后是几点 (15 分)有时候人们用四位数字表示一个时间,比如 1106 表示 11 点零 6 分。现在,你的程序要根据起始时间和流逝的时间计算出终止时间。
  13. 2016阿里安全工程师实习生招聘笔试题
  14. [IC]浅谈嵌入式MCU软件开发之中断优先级与中断嵌套
  15. 思科和思杰联袂提供全面的桌面虚拟化解决方案
  16. php上传文件自动解压,PHP自动解压上传的rar文件
  17. Java基础之MySQL(二)
  18. 如何判断应变片式压力传感器是否损坏
  19. pkt2flow的使用
  20. 程序员应该如何应对35岁中年危机?

热门文章

  1. python2.X在linux上的安装
  2. spark之4:编程指南
  3. 数据挖掘之关联分析七(非频繁模式)
  4. 构建机器学习系统步骤
  5. iOS开发月报#10|201904
  6. Linux中find命令详解
  7. ubuntu设置自启动服务程序
  8. JBPM学习(一):实现一个简单的工作流例子全过程
  9. Parsing XML in J2ME
  10. 致SEO初学者:学习SEO要注意的几个问题