HDU,hduacm

來源:互聯網
上載者:User

HDU,hduacm

Problem DescriptionHere is a game for two players. The rule of the game is described below:

● In the beginning of the game, there are a lot of piles of beads.

● Players take turns to play. Each turn, player choose a pile i and remove some (at least one) beads from it. Then he could do nothing or split pile i into two piles with a beads and b beads.(a,b > 0 and a + b equals to the number of beads of pile i after removing)

● If after a player's turn, there is no beads left, the player is the winner.

Suppose that the two players are all very clever and they will use optimal game strategies. Your job is to tell whether the player who plays first can win the game. 
InputThere are multiple test cases. Please process till EOF.

For each test case, the first line contains a postive integer n(n < 105) means there are n piles of beads. The next line contains n postive integer, the i-th postive integer ai(ai < 231) means there are ai beads in the i-th pile. 
OutputFor each test case, if the first player can win the game, ouput "Win" and if he can't, ouput "Lose" 
Sample Input

1121 131 2 3
 
Sample Output
WinLoseLose題意:取完石頭後,可以再把這堆分成兩個堆思路:類似Nim遊戲:異或起來0為先手輸
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>typedef __int64 ll;using namespace std;int main() {int n;while (scanf("%d", &n) != EOF) {ll ans = 0;ll tmp;for (int i = 0; i < n; i++) {scanf("%I64d", &tmp);ans ^= tmp;}if (ans == 0)printf("Lose\n");else printf("Win\n");} }



hdu acm 1052

嘗試:
4
1 2 4 5
2 3 3 4
0
關於速度慢是因為排序,嘗試qsort。
——————————————————————————————
qsort見:
www.cppreference.com/wiki/c/other/qsort
——————————————————————————————
2
2 3
1 3
0
再有什麼問題追加點分吧
 
簡單題hdu 1004 Runtime Error(ACCESS_VIOLATION)

問題真不少...下面代碼能ac
STACK_OVERFLOW是棧空間溢出,什麼是棧請自行google,你這裡表現為a開得太大了,將大數組開到外面就可以解決。
ACCESS_VIOLATION一般是數組越界了,你這裡表現為b開的太小,當n>100時,i、j下標就會越界

#include<stdio.h>
#include<string.h>
char a[1001][20]; //500改小就成WA,改大就STACK_OVERFLOW
int main()
{

int b[1001],i,maxi,max,j,n;
while(scanf("%d",&n)!=EOF)
{
if(n==0) break; //題幹給出的結束條件,請不要忽略
for(i=0;i<n;i++)
scanf("%s",a[i]);
for(i=0;i<n;i++)
{
b[i]=0;
for(j=i+1;j<n;j++)
if(strcmp(a[j],a[i])==0)
b[i]++;
}
max=b[0];
for(i=0;i<n;i++)
if(b[i]>=max)
{ max=b[i];
maxi=i;
}
printf("%s\n",a[maxi]);
}
return 0;
}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.