20130820 【南华大学 ACM】 个人选拔赛第二场 【B . SUME】
2013-08-21 20:27
465 查看
Problem B: SUME
Time Limit: 1 Sec Memory Limit:32 MB
Description
Once upon a time, there existed a sequence A consisting of N positive integers. You don't know thesequence itself, but you do know the sum of every two elements of the sequence. Find the sequence A!
Input
The first line of input contains the positive integer N (2 ≤ N ≤ 1000).Each of the following N lines contains N positive integers smaller than or equal to 100 000, forming
the table S. The following relations hold: S(i, j) = A [i] + A [j] for i ≠ j, and S(i, j) = 0 for i = j. Here S(i,
j) denotes the number in the ith row and jth column of the table, and A [i] denotes the ith element of the
sequence A.
It is guaranteed that for any input data set there exists a unique sequence of positive integers A with
the given properties.
Output
The first and only line of output must contain the required sequence A (in the form of N space-separated positive integers).
Sample Input
2 0 2 2 0 4 0 3 6 7 3 0 5 6 6 5 0 9 7 6 9 0
Sample Output
1 1 2 1 4 5
HINT
--------------------------------------------------------------------------------------------------------------------------以第一行的数据为例( n 个元素),各元素为: 0, a1+a2, a1+a3, a1+a4, …… , a1+an;
显然,只要求出 a1, 那么 a2, a3, a4, …… ,an 都能一一求出。
求 a1 就需要 第二行 第三个元素( a[2][3] = a2 + a3 )
a[1][3] - a[2][3] = a1 - a2 ;
a[1][3] - a[2][3] + a[1][2] = 2 * a1 ;
所以: a1 = ( a[1][3] - a[2][3] + a[1][2] ) / 2 ;
接下来的,你懂的……
上述情况为 当 n>2 时。当 n=2 时,我就不懂了,如下情况:
0 3
3 0
会输出什么?( a1 = ? , a2 = ? )
--------------------------------------------------------------------------------------------------------------------------
#include<stdio.h> int main(){ int n,i,j,s[1010],ss[1010],a[1010],c; while( EOF != scanf("%d",&n) ){ for(i=1;i<=n;i++) // 第一行 数据 scanf("%d",&s[i]); for(i=1;i<=n;i++) // 第二行 数据 scanf("%d",&ss[i]); if( 2==n ){ // 当 n=2 时 a[1]=a[2]=s[2]/2; if( 2*a[1] != s[2] ) a[2]=a[1]+1; printf("%d %d\n",a[1],a[2]); continue; } for(i=3;i<=n;i++) for(j=1;j<=n;j++) scanf("%d",&c); a[1] = a[i] = (s[3] - ss[3] + s[2] )/2; // 求 a1 printf("%d ",a[1]); // 输出 a1 for(i=2;i<=n;i++){ a[i] = s[i] - a[1]; if( i!=n ) printf("%d ",a[i]); else printf("%d\n",a[i]); } } return 0; }
相关文章推荐
- 20130820 【南华大学 ACM】 个人选拔赛第二场 【C . DOBRI】
- 20130820 【南华大学 ACM】 个人选拔赛第二场 【A . BAKA】
- 南华大学ACM个人练习 第二场 D: The mell hall
- 南华大学ACM第一场个人联系赛 A Eming
- 南华大学ACM 个人练习第一场 B.Arithmetic Progression
- 20130709 【南华大学 ACM】 新生赛第二场 【B. Dating With Girls】
- 南华大学ACM个人连续第一场 E.Function
- 20130709 【南华大学 ACM】 新生赛第二场 【D: The mell hall】
- 湖南工业大学个人选拔赛第二场 解题报告
- 湖南工业大学个人选拔赛第二场 解题报告
- 湖南工业大学个人选拔赛第二场 解题报告
- 湖南工业大学个人选拔赛第二场 解题报告
- 省赛选拔赛——个人赛第二场
- 20130709 【南华大学 ACM】 新生赛第二场 【F. Little Sheep and a paper】
- 20130709 【南华大学 ACM】 新生赛第二场 【G. Matrix】
- 南华大学个人练习第三场F.Help Johnny
- 南华大学暑假个人练习 1032: 机器人II
- 2013 ACM/ICPC Asia Regional Online — Warmup 个人总结
- 关于参加ACM-ICPC的 ACMer的 个人训练问题
- 我们为什么选择acm(个人观点)