20130820 【南华大学 ACM】 个人选拔赛第二场 【B . SUME】
来源:互联网 发布:微耕门禁数据库表结构 编辑:程序博客网 时间:2024/04/28 04:51
Problem B: SUME
Time Limit: 1 Sec Memory Limit: 32 MBDescription
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
20 22 040 3 6 73 0 5 66 5 0 97 6 9 0
Sample Output
1 12 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; // 求 a1printf("%d ",a[1]); // 输出 a1for(i=2;i<=n;i++){a[i] = s[i] - a[1];if( i!=n )printf("%d ",a[i]);elseprintf("%d\n",a[i]);}}return 0;}
- 20130820 【南华大学 ACM】 个人选拔赛第二场 【B . SUME】
- 20130820 【南华大学 ACM】 个人选拔赛第二场 【A . BAKA】
- 20130820 【南华大学 ACM】 个人选拔赛第二场 【C . DOBRI】
- 南华大学ACM 个人练习第一场 B.Arithmetic Progression
- 南华大学ACM个人练习 第二场 D: The mell hall
- 20130709 【南华大学 ACM】 新生赛第二场 【B. Dating With Girls】
- 南华大学ACM第一场个人联系赛 A Eming
- 南华大学ACM个人连续第一场 E.Function
- 20130709 【南华大学 ACM】 新生赛第二场 【G. Matrix】
- 20130709 【南华大学 ACM】 新生赛第二场 【D: The mell hall】
- 20130709 【南华大学 ACM】 新生赛第二场 【F. Little Sheep and a paper】
- 20130707 【南华大学 ACM】 新生赛第一场 【B.Arithmetic Progression】
- 20130712 【南华大学 ACM】 新生赛第三场 【B. A simple problem】
- 南华大学暑假个人练习第三场 B. A simple problem
- 20130707 【南华大学 ACM】 新生赛第一场 【A.Eming】
- 20130707 【南华大学 ACM】 新生赛第一场 【D.Brackets】
- 20130707 【南华大学 ACM】 新生赛第一场 【E.Function】
- 南华大学个人练习第三场F.Help Johnny
- sqlite数据库使用
- 改变 WID 的位置
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第三篇:ASP.NET MVC全局观
- Stanford机器学习---第四讲. 神经网络的表示 Neural Networks representation
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第四篇:传递表单数据
- 20130820 【南华大学 ACM】 个人选拔赛第二场 【B . SUME】
- 一位天才创业者从4位大佬身上学到的:懂得放弃
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第五篇:MVC整合Ajax
- Delphi学习之Assigned使用
- hdu 1890 Robotic Sort (splay tree伸展树)
- 算法之递归算法(斐波那契数列之美)(100级阶梯,1,2步,几种方法)
- Android监控程序本身被卸载方法汇总
- 外网访问局域网Tomcat服务器的设置过程
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第六篇:拦截器