Attack City and Capture Territory & 取石子(博弈)
问题 : H. Attack City and Capture Territory
时间限制: 3 Sec 内存限制: 128 MB提交: 5 解决: 5
[提交][状态]
题目描述
The Three Kingdoms period was a relatively famous periodin the history of China. From the Battle of Chibi (AD 211) to the reunificationof China in the Western Jin Dynasty(AD 280). During the period, Cao's WeiState, Liu's Shu State, and Sun's Wu Guo's Three Kingdoms stood together.Therefore, it was called the Three Kingdoms period.
In the last years of the Eastern Han Dynasty, Dong_ Zspecialized in power , the coalition forces of the world's princes crusadeagainst each other. Among them, Liu_B and Sun_Q, who are school students, alsoparticipated in the crusade.
In AD 215 , Liu_B and Sun_Q simultaneously attackedJingZhou and directly threatened Dong Z's city. There were N firepower pointson the high wall, each fire point with different s trength Xi . Liu_B and Sun_Q looked at the high walls and the stronggates, they did not attack the city traightaway. They negotiate to attack firepower point alternately. Who breaksthrough the last firepower point, he will win the city.
Because of limited weaponry, weapons of each side canonly attack one firepower at a time. But they can control whether completelydestroy this firepower point or weaken the strength of firepower point.
Liu_B has a strong think-tank. After calculation, hefinds out who will attack first , who will more likely win the city .
输入
The first line of the inputcontains one integer T, which is the number of test cases (1<=T<=10). Each test casespecifies:
* Line 1: N ( 1 ≤ N ≤ 100 )
* Line 2: X1 X2… Xn ( 1 <= Xi<=1000 i=1…. n)
输出
For each test case , print “Liu_B is sure to win.” Or “Liu_Bis not sure to win.” , suppose Liu_B first attacks.
样例输入
321 323 351 2 3 4 5
样例输出
Liu_B is sure to win.Liu_B is not sure to win.Liu_B is sure to win.
大意是有n个东西,可以全部破坏或者只破坏一部分,最后破坏的人获胜。
#include<stdio.h>
#define N 120
int a[N];
int main()
{
int sum,n,t,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sum=a[0];
for(i=1;i<n;i++)
sum=sum^a[i];
if(sum==0)
printf("Liu_B is not sure to win.\n");
else
printf("Liu_B is sure to win.\n");
}
return 0;
}
有一道相同的题是给出n堆石子,每次可以从一堆中取出部分石子或者全部取完,谁取完最后一个石子获胜。一样的道理。