2261: flower
Time Limit: 1 Sec Memory Limit: 128 MBCommits: 283 Resolved: 175
[ Commit ][ Status ][ Discussion Board ][Submission By: admin ]
Topic description
It's Teacher's Day again, and there are n children who plan to visit Teacher Hua.
Of course, you have to buy flowers when you go to see the flower teacher. However, some local (xue) ho (ba) bought too many flowers, which made other children very embarrassed, so the children came up with a solution:
They plan not to directly tell Teacher Hua how many flowers each person bought, but to encrypt it in some way (too naive), the encryption method is as follows:
Suppose the i-th child gave Ai flowers (Ai > 0), then T(j,k) is defined as follows
T (j, k) = Aj + Ak (j ≠ k)
T (j, k) = 0 (j = k)
Then they tell Teacher Hua all T(j,k).
Of course, the kind flower teacher doesn't care about who sent how many flowers, but you are curious to know which children are more earthy (xue) and proud (ba).
enter
The first line contains a positive integer n. (2 <= n <= 1000, 2 <= T(j,k) <= 1000)
The next n lines each contain n non-negative integers T(j,k).
output
Output a line of n positive integers Aj separated by spaces, if there are multiple possibilities to output the smallest sum of all unknowns.
sample input
40 3 6 73 0 5 66 5 0 97 6 9 0
Sample output
2 1 4 5
It was made by my teammates during the game, and the questions will be added after the game
Ideas: It can be seen from the question: T(a,b)+T(a,c)-T(b,c)=2*a; so you can use this method to calculate each item;
Code:
#include<queue> #include<cmath> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> using namespace std; int a[1110][1110]; int b[1100]; intmain() { int n; while(scanf("%d",&n)!=EOF) { int i,j,sum=0,ans=0; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(i=0; i<n; i++) { for(j=0; j<n; j++) { scanf("%d",&a[i][j]); } } for(i=0; i<n; i++) { for(j=0;j<n-1;j++) { if(i!=j&&i!=j+1) { b[i]=(a[i][j]+a[i][j+1]-a[j][j+1])/2; break; } } } for(i=0; i<n; i++) printf("%d ",b[i]); printf("\n"); } return 0; }