ZOJ Problem Set - 3860Find the Spy
--------------------------------------------------------------------------------
Time Limit: 2 Seconds Memory Limit: 65536 KB
--------------------------------------------------------------------------------
Whoooa! There is a spy in Marjar University. All we know is that the spy has a special ID card. Please find him out!
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains a integer N (3 <= N <= 100), which describes that there are N students need to be checked.
The second line contains N integers indicating the ID card number of N students. All ID card numbers are 32-bit integers.
Output
For each test case, output the ID card number which is different from others.
Sample Input
3
10
1 1 1 1 1 1 1 1 6 1
3
9 9 8
5
90016 90016 90016 2009 90016
Sample Output
6
8
2009
--------------------------------------------------------------------------------
Author: DAI, Longao
Source: The 15th Zhejiang University Programming Contest
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cmath>
//#include<bits/stdc++.h>
#include<map>
using namespace std;
template<class T>inline T read(T&x)
{
char c;
while((c=getchar())<=32)if(c==EOF)return 0;
bool ok=false;
if(c=='-')ok=true,c=getchar();
for(x=0; c>32; c=getchar())
x=x*10+c-'0';
if(ok)x=-x;
return 1;
}
template<class T> inline T read_(T&x,T&y)
{
return read(x)&&read(y);
}
template<class T> inline T read__(T&x,T&y,T&z)
{
return read(x)&&read(y)&&read(z);
}
template<class T> inline void write(T x)
{
if(x<0)putchar('-'),x=-x;
if(x<10)putchar(x+'0');
else write(x/10),putchar(x%10+'0');
}
template<class T>inline void writeln(T x)
{
write(x);
putchar('\n');
}
//-------ZCC IO template------
const int maxn=11;
const double inf=999999999;
#define lson (rt<<1),L,M
#define rson (rt<<1|1),M+1,R
#define M ((L+R)>>1)
#define For(i,t,n) for(int i=(t);i<=(n);i++)
//typedef long long LL;
typedef double DB;
typedef pair<int,int> P;
#define bug printf("---\n");
#define mod 10007
map<int,int> mp;
map<int,int>::iterator it;
int main()
{
//#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
//freopen("zccccc.txt","w",stdout);
//#endif // ONLINE_JUDGE
int n,m,i,j,t,k;
int T;
read(T);
while(T--)
{
read(n);
mp.clear();
while(n--)
{
read(k);
mp[k]++;
}
it=mp.begin();
while(it!=mp.end())
{
if(it->second==1)
{
writeln(it->first);break;
}
it++;
}
}
return 0;
}

这是一个关于ZOJ Problem Set中3860题目的解析,题目要求找出间谍,间谍的ID与其他人不同。给定每个测试用例包含学生数量N和所有学生的32位ID,你需要输出与众不同的ID。示例输入和输出分别展示了不同测试用例的结果,如当N为10时,输出6,当N为3时,输出8,当N为5时,输出2009。该问题可以利用STL中的map建立简单的查询表来解决。
&spm=1001.2101.3001.5002&articleId=45059457&d=1&t=3&u=551235d32da74191ad432cd7b0387126)
1091

被折叠的 条评论
为什么被折叠?



