# PAT 解题报告 1041. Be Unique (20)

### 1041. Be Unique 题目描述：

Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1, 104]. The first one who bets on a unique number wins. For example, if there are 7 people betting on 5 31 5 88 67 88 17, then the second one who bets on 31 wins.

### 1041. Be Unique 算法分析：

```// TLE, g++ complier
#include <cstdio>

#define REP(i,n) for(int i=0;i<(n);++i)
#define MAXBETS 10005
#define MAXN 100005

using namespace std;

int counts[MAXBETS];
int bets[MAXN];
int N;

int main(void) {
scanf("%d", &N);
REP(i,N) {
scanf("%d", &bets[i]);
counts[bets[i]]++;
}
bool found = false;
REP(i, N) {
if(1 == counts[bets[i]])
{
printf("%d\n", bets[i]);
found = true;
break;
}
}
if(!found) printf("None\n");
return 0;
}

// TLE with gcc compiler
#include <stdio.h>
#define MAXBETS 10005
#define MAXN 100005

int counts[MAXBETS];
int bets[MAXN];
int N;

int main(void) {
scanf("%d", &N);
int i = 0;
for(i = 0; i < N; ++i) {
scanf("%d", &bets[i]);
counts[bets[i]]++;
}
int found = 0;
for(i = 0; i < N; ++i) {
if(1 == counts[bets[i]])
{
printf("%d\n", bets[i]);
found = 1;
break;
}
}
if(!found) printf("None\n");
return 0;
}

// AC: with gcc compiler
// last two cases takes 10 ms, the limit is 20ms
0	答案正确	0	790	11/11
1	答案正确	0	750	1/1
2	答案正确	0	790	2/2
3	答案正确	0	790	2/2
4	答案正确	10	850	2/2
5	答案正确	10	860	2/2
#include <stdio.h>

int counts[10005];
int bets[100005];
int N;

int main(void) {
scanf("%d", &N);
int i = 0;
for(i = 0; i < N; ++i) {
scanf("%d", &bets[i]);
counts[bets[i]]++;
}
for(i = 0; i < N; ++i) {
if(1 == counts[bets[i]]) {
printf("%d\n", bets[i]);
return 0;
}
}
printf("None\n");
return 0;
}
```

### 1041. Be Unique  注意点：

Written on January 10, 2014