20130820 【南华大学 ACM】 个人选拔赛第二场 【B . SUME】

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 the
sequence 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


--------------------------------------------------------------------------------------------------------------------------


  1. 以第一行的数据为例( n 个元素),各元素为: 0, a1+a2, a1+a3, a1+a4, …… , a1+an;
  2. 显然,只要求出 a1, 那么 a2, a3, a4, …… ,an 都能一一求出。
  3. 求 a1 就需要 第二行 第三个元素( a[2][3] = a2 + a3 )
  4. a[1][3] - a[2][3] = a1 - a2 ;
  5. a[1][3] - a[2][3] + a[1][2] = 2 * a1 ;
  6. 所以: a1 = ( a[1][3] - a[2][3] + a[1][2] ) / 2 ;
  7. 接下来的,你懂的……
  8. 上述情况为 当 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值