1036: Xiaoxi Tables time limit: 1 Sec memory limit: MB
Submitted by: 417 Resolution: 283
Submitted State [Discussion Version] Title Description Gardon yesterday gave little hope to work, that is, according to a number of N (3<=n<=100) not more than 5000 of the positive integer number 22 is added to N (N-1)/2 and, and then sorted them. For example, if the tables contain four number 1,3,4,9, the correct answer is 4,5,7,10,12,13. Little hope after finishing homework out for a while, but the afternoon home found that the original table is missing, fortunately she made the answer is still in, you can help her according to her answer calculate the original tables? The input contains multiple sets of data, each set of data starting with an N, and the next line has n (N-1)/2 numbers in order of size, which is the answer that is done by Xiao-Nozomi. The file ends with a 0.
Suppose the input guarantees the existence and uniqueness of the solution. Output for each set of data, output the original tables. They should also be arranged in order. Sample input
44 5 7 10 12 1345 6 7 8 9 100
Sample output
1 3 4 92 3 4 6
#include <iostream>
#include <vector>
using namespace std;
int solve (int x,int s2,int s1) {
if ((X+S2-S1)%2==0) {
return (X+S2-S1)/2;
}
Else
return 0;
}
Int main () {
for (;;) {
int n;
cin>>n;
if (n==0) break;
else{
Int a[n];
Vector<int> s (n (n-1)/2);
for (int i=0;i<n* (n-1)/2;i++) {
Cin>>s[i];
}
for (int i=2;i<n* (n-1)/2;i++) {
if (solve (s[i],s[1],s[0])!=0) {
A[2]=solve (s[i],s[1],s[0]);
S[i]=0;
Break
}
}
A[1]=s[0]-s[1]+a[2];
A[0]=S[0]-A[1];
S[0]=0;s[1]=0;
int j=2;
for (int i=3;i<n;i++) {
for (int j=2;j<n* (n-1)/2;j++) {
if (s[j]!=0) {
a[i]=s[j]-a[0];}
for (int k=0;k<i;k++) {
for (int q=0;q<n* (n-1)/2;q++) {
if (S[q]==a[i]+a[k]) {
s[q]=0;
}
}
}
}
}
for (int i=0;i<n;i++) {
if (i==0)
Cout<<a[i];
else
cout<< "" <<a[i];
}
cout<<endl;
}
}
return 0;
}
1036: Tables for Xiaoxi