日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ccf报数游戏java_ccf 201712 02 (游戏)

發(fā)布時間:2023/12/31 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ccf报数游戏java_ccf 201712 02 (游戏) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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

這里我們來詳細(xì)講解一下圓桌問題的相關(guān)題目

第一道一定是hdu的4841了,罪惡的源頭

圓桌上圍坐著2n個人。其中n個人是好人,另外n個人是壞人。如果從第一個人開始數(shù)數(shù),數(shù)到第m個人,則立即處死該人;然后從被處死的人之后開始數(shù)數(shù),再將數(shù)到的第m個人處死……依此方法不斷處死圍坐在圓桌上的人。試問預(yù)先應(yīng)如何安排這些好人與壞人的座位,能使得在處死n個人之后,圓桌上圍坐的剩余的n個人全是好人。

輸入:多組數(shù)據(jù),每組數(shù)據(jù)輸入:好人和壞人的人數(shù)n(<=32767)、步長m(<=32767);

輸出:對于每一組數(shù)據(jù),輸出2n個大寫字母,‘G’表示好人,‘B’表示壞人,50個字母為一行,不允許出現(xiàn)空白字符。相鄰數(shù)據(jù)間留有一空行。

輸入

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下標(biāo)從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;

}

圓桌問題的簡單應(yīng)用

題目

“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(chǎn)’-‘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;

}

總算是回到了游戲這題,這題其實就是屬于圓桌問題的變種,關(guān)鍵就在于把報數(shù)的過程轉(zhuǎn)化為每隔幾個人就會被淘汰的問題,這就相當(dāng)于n個人只有一個是好人,從第一個人開始每隔幾個人就會抹殺一個壞人,最終剩下一個好人勝出

關(guān)鍵:處理這個隔幾個人的問題

題目請到ccf官網(wǎng)自提

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,并且淘汰人數(shù)加1

}

else m++;//這里m就是距離上一次淘汰所間隔人數(shù)

cnt++;//cnt表示所報的數(shù)

}

cout<< res[0] <

return 0;

}

持續(xù)更新中。。。。

總結(jié)

以上是生活随笔為你收集整理的ccf报数游戏java_ccf 201712 02 (游戏)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久精品国产亚洲AV高清综合 | 日韩一区二区不卡视频 | 性色福利 | 清清草免费视频 | jzzjzz日本丰满成熟少妇 | 日本伦理片在线看 | 欧美人喂奶吃大乳 | 999久久久精品视频 亚洲视频精品在线 | 国产一区在线观看视频 | 成人小视频免费 | a国产在线| 污视频网站入口 | 欧美性猛交久久久久 | 99精品视频一区二区三区 | 国精产品一区一区三区 | 成人在线天堂 | 调教奶奴 | 先锋资源av | 国产麻豆一精品一男同 | 亚洲 欧美 激情 小说 另类 | 精品中文字幕一区二区三区 | 久久99日| 国产美女被草 | 91极品美女| 蜜臀久久99精品久久久久宅男 | 99这里都是精品 | 97超碰人人澡人人爱学生 | av中文一区 | 神马午夜888| 国产精品三级 | 欲涩漫入口免费网站 | 野花社区视频在线观看 | 欧美性激情| 亚洲av无码一区二区二三区 | 日韩成人一区二区三区 | 亚洲综合一 | 久草热在线视频 | 99er久久| 国产精品久久久久影院 | 极品美女高潮出白浆 | 综合av网 | 国产一区二区视频播放 | 亚洲丝袜视频 | 少妇搡bbbb搡bbb搡小说 | 神马久久久久久久久 | 日本中文字幕观看 | 日产电影一区二区三区 | a级在线观看视频 | 国产视频www | 国内自拍视频在线播放 | 欧美日本韩国一区二区 | 午夜免费视频观看 | 国产又黄又猛 | 成人做爰9片免费视频 | 免费看黄色三级三级 | 亚洲欧美国产另类 | 都市激情自拍偷拍 | 亚洲免费视频播放 | 美女破处视频 | 高清日韩av | 亚洲国产黄色av | 骑骑上司妻电影 | 国产全肉乱妇杂乱视频 | 尤物国产 | 成人动漫av | 香蕉在线网站 | 日韩女优在线视频 | 成人小说亚洲一区二区三区 | 日韩欧美视频 | 天天综合91 | 白石茉莉奈番号 | 黄色资源在线播放 | www.浪潮av.com | 新呦u视频一区二区 | 美女被男生免费视频 | 亚洲日本影院 | 囯产精品久久久久久 | jizz在线免费观看 | 另类视频一区 | 8050午夜二级 | 狂野欧美性猛交xxxx | 青青青网 | 朝桐光av一区二区三区 | 中文字幕少妇在线三级hd | 久久精工是国产品牌吗 | 黄色三级视频 | 久久99精品视频 | 国产免费成人 | 人人干97 | 中文字幕人乱码中文字 | 国产精品第七页 | 欧美美女一区二区三区 | 日韩影视一区二区三区 | 精品偷拍网| 久久综合伊人77777麻豆最新章节 | 人人妻人人澡人人爽精品欧美一区 | 性生生活大片又黄又 | 欧美三区 | 91网国产 |