Hdu--2515 (规律)
2014-07-08 21:52:31
详情:黑书
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 using namespace std; 6 int main(){ 7 int tmp,n,sum,s[5000],hash[10005],num[55],cnt = 0; 8 memset(hash,0,sizeof(hash)); 9 scanf("%d",&n); 10 sum = n * (n - 1) / 2; 11 for(int i = 0; i < sum; ++i){ 12 scanf("%d",&s[i]); 13 hash[s[i]] = 1; 14 } 15 sort(s,s + sum); 16 for(int i = 2; i < sum; ++i){ 17 tmp = s[0] + s[1] - s[i]; 18 if((int)(1.0 * tmp) / 2 == tmp / 2){ 19 int a = tmp / 2; 20 while(cnt < n){ 21 for(int j = 0; j < cnt; ++j) hash[a + num[j]] = 0; 22 num[cnt++] = a; 23 for(int j = 0; j < sum; ++j) 24 if(hash[s[j]]){ 25 a = s[j] - num[0]; 26 break; 27 } 28 } 29 break; 30 } 31 } 32 for(int i = 0; i < cnt; ++i) 33 printf("%d\n",num[i]); 34 return 0; 35 }