URAL 1023 Buttons(巴什博弈水题)
2014-08-05 20:45
357 查看
1023.Buttons
Timelimit:2.0secondMemorylimit:64MB
Background
Asyousurelyalreadyknow,YekaterinburghasgottenitsrighttoholdTheSummerOlympicGamesofthe2032.ItisplannedthatitwillbeallowedtoRussiaasacountry-organizertoemendaprogramofthegamesabit.So,inordertoimprovethecommandresultithasbeendecidedtoreplacethecompetitioningymnasticsbythecompetitioninthenewgame"Buttons".Therulesofthegameareverysimple.There’sasmallheapofKbuttonsbeforetwoplayers.Theplayersinturnstakebuttonsfromtheheap,moreover,atatimeonecantakeanumberofbuttonsfrom1uptoL.Theonewhotakesthelastbuttonisthewinner.
TherulesoftheOlympicGameswillbeabitharderthenusual.Theone,whoistomakeafirststepaccordingtoalot,hasanopportunitytofixanumberKwiththefollowingrestrictiontoit:3≤K≤108(thatistheexactnumberofbuttonsthathasbeenpreparedfortheOlympictournament).TheplayerwhoistomakethesecondstepfixesanumberLthatsatisfiesthefollowingconditions2≤L<K.
Problem
Averycrucialtaskisgiventoyourteam:youaretowriteaprogramthatshouldhelpthesecondplayertomakehischoice.Inotherwords,givenanumberKyourprogramistofindanumberLthatguarantiesavictorytothesecondplayerwithapropergameofbothsides.So,forinstance,thereareonlythreebuttonsintheheap,thechoiceL=2providesforthevictoryofthesecondplayer.Really,ifthefirstplayertakesonlyonebuttonathisturn,thesecondonewins,takingthetwolastbuttons.Onthecontrary,ifthefirstonetakestwobuttons,thesecondonewins,takingthelastbutton.
Input
Thestandardinputconsistsofoneline,whichcontainsanonlyintegernumberK—anumberofbuttonsintheheap,thathasfixedthefirstplayerathisturn.Output
TothestandardoutputyouaretowritetheonlynumberL—themaximalnumberofbuttonsthatcanbetakenatatimewhichprovidesforthevictoryofthesecondplayer.IfthereareseveralthosenumbersL,youshouldwritetheleast.Iftherearenosuchnumbers,youaretowrite0tothestandardoutput.Sample
input | output |
---|---|
3 | 2 |
典型的巴什博弈啦~
#include<iostream> #include<cstring> usingnamespacestd; intK,L; intmain(){ while(~scanf("%d",&K)){ intjilu; intfalg=false; for(inti=3;i<=K;i++){ if(K%i==0){ falg=true; printf("%d\n",i-1); break; } } if(!falg) printf("0\n"); } return0; }
相关文章推荐
- URAL 1023 Buttons 博弈
- URAL 1023 Buttons 博弈
- Ural 1023. Buttons
- ural 2068 - Game of Nuts 博弈水题
- POJ 2368|URAL 1023|Buttons|博弈论
- hdu 1846 Brave Game (巴什博弈 最简单的博弈水题)
- POJ 2368(Buttons) 巴什博弈变形 Java
- POJ 2368 Buttons(巴什博弈变形)
- 杭电 2188(博弈 水题 巴什博弈)
- Ural 1023. Buttons
- URAL 1023 Buttons
- E - Buttons URAL - 1023
- ural 1023 Buttons
- URAL 1023 Buttons
- HDU2149 (巴什博弈)
- HDU 2188 经典巴什博弈
- hdoj.1564 Play a game【博弈水题】 2015/03/27
- HDU 4764 Stone(巴什博弈变形)
- 巴什博弈
- hdu 1846 Brave Game (巴什博弈)