Time Limit: 5.0 Seconds Memory Limit: 5000K
Total Runs: 225 Accepted Runs: 77
In HDFS( Hadoop Distributed File System), each data may have a lot of copies in case of data lose.
This problem, every data has its own id, from 1 to n. To make things simple, each data has only two copies.
This time, the HDFS is cracked by some stupid reason. Fortunately, tmeteorj knows that there are actually 2 data lost by his keen intuition.
Now, it is your time to show your value of life. You should tell tmeteorj the id of lost data.
INPUT
First line, there will a number T(1≤T≤10), means the test case of this problem.
After this, each line is first a number n(1≤n≤5000000), means data id is from 1 to n. Then there will be 2(n-1) numbers means the id of data in health state.
OUTPUT
For each case, print the lost id of data. The smaller id is in the front of the bigger one.
Sample Input
3 4 1 1 2 3 4 4 4 1 2 3 1 2 4 4 2 3 4 2 3 1
Sample Output
2 3 3 4 1 4
题目大意:求数据中没有出现两次的那两个数。
这题主要是卡内存...坑
对于这种题目,set map都会爆内存,所以考虑用biset记录一下出现没有。
/* *********************************************** Author :guanjun Created Time :2016/6/25 12:20:55 File Name :tju4119.cpp ************************************************ */ #include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #include <bitset> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 10010 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; bitset<5010000>b; vector<int>v; bitset<5010000>c; int main() { // freopen("in.txt","r",stdin); int t,n,x; cin>>t; while(t--){ cin>>n; b.reset(); c.reset(); int w=0; for(int i=1;i<=n*2-2;i++){ scanf("%d",&x); w^=x; if(b[x]==1){ b[x]=0; c[x]=1; } else{ b[x]=1; c[x]=1; } } v.clear(); if(w==0){ for(int i=1;i<=n;i++){ if(c[i]==0){ v.push_back(i); v.push_back(i); break; } } } else{ for(int i=1;i<=n;i++){ if(b[i]==1){ v.push_back(i); } } } cout<<v[0]<<" "<<v[1]<<endl; } return 0; }