标签:
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.
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.
For each case, print the lost id of data. The smaller id is in the front of the bigger one.
3 4 1 1 2 3 4 4 4 1 2 3 1 2 4 4 2 3 4 2 3 1
2 3 3 4 1 4
Source: TJU School Competetion 2015
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; int main() { long long n,i,a,b,x,y,d,z; cin>>z; while(z--) { cin>>n; a = 2,b = 2; for(i = 0;i<2*n-2;i++) { long long t; scanf("%lld",&t); a += n-i/2-t; b += (n-i/2)*(n-i/2)-t*t; } d = sqrt(2*b-a*a); x = (a-d)/2,y = (a+d)/2; cout<<x<<" "<<y<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/wos1239/p/4563234.html