1202: Stone-scissors-cloth
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 293 Solved: 141
[Submit][Status][Web Board]
Description
現在一共有N個人(分別記爲1, 2, …, N)在玩剪刀石頭布,如果知道他們每個人都出了什麼,你能找出來誰是winner嗎?
當且僅當一個人可以贏其他所有人時,才稱這個人是winner。
我們將剪刀記作2,石頭記作0,布記作5,那麼勝負關係就應當是2能贏5,5能贏0,0能贏2。
Input
輸入數據的第一行包含一個整數T ( 1 <= T <= 150),表示接下來一共有T組測試數據。
每組測試數據的第一行包含一個整數N (2 <= N <= 100000)表示一共有N個人在玩剪刀石頭布,接下來一行一共有N個數,每個數均爲0、2或5中的某一個,依次描述了這N個人分別出了什麼,其中第i個整數描述了第i個人出了什麼。
Output
對於每組數據,用一行輸出一個整數表示winner是第幾個人([1, N]中的某個整數)。
如果不存在winner,則用一行輸出“No winner”(不包括引號)。
Sample Input
3
5 5 2
3
2 0 0
3
0 2 5
Sample Output
No winner
No winner
HINT
Source
題意:
告訴你石頭剪刀布的規則,問是否有唯一一人獲勝,有輸出編號,沒有輸出“No winner”。
思路:
簡單模擬
/*************************************************************************
> File Name: B.cpp
> Author: BSlin
> Mail:
> Created Time: 2013年10月03日 星期四 12時15分26秒
************************************************************************/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define MP make_pair
#define INF (1<<30)
#define PI acos(-1.0)
#define esp 1e-8
const int dx[4]={0,0,0,0};
using namespace std;
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#if defined (_WIN32) || defined (__WIN32) || defined (WIN32) || defined (__WIN32__)
#define LL __int64
#define LLS "%" "I" "6" "4" "d"
#else
#define LL long long
#define LLS "%" "l" "l" "d"
#endif
#define M 100010
struct node {
int x,id;
}data[M];
int cnt[5];
int main(int argc, char** argv) {
//read;
int t,n;
scanf("%d",&t);
while(t--) {
memset(cnt,0,sizeof(cnt));
scanf("%d",&n);
for(int i=1; i<=n; i++) {
scanf("%d",&data[i].x);
data[i].id = i;
if(data[i].x == 0) {
cnt[0] ++;
}
else if(data[i].x == 2) {
cnt[1] ++;
}
else if(data[i].x == 5) {
cnt[2] ++;
}
}
if(cnt[0] != 0 && cnt[1] != 0 && cnt[2] != 0) {
printf("No winner\n");
continue;
}
else if(cnt[0] == 1 && cnt[1] != 0 && cnt[2] == 0) {
for(int i=1; i<=n; i++) {
if(data[i].x == 0) {
printf("%d\n",data[i].id);
break;
}
}
}
else if(cnt[0] == 0 && cnt[1] == 1 && cnt[2] != 0) {
for(int i=1; i<=n; i++) {
if(data[i].x == 2) {
printf("%d\n",data[i].id);
break;
}
}
}
else if(cnt[0] != 0 && cnt[1] == 0 && cnt[2] == 1) {
for(int i=1; i<=n; i++) {
if(data[i].x == 5) {
printf("%d\n",data[i].id);
break;
}
}
}
else printf("No winner\n");
}
return 0;
}