题解:P13420 [COCI 2012/2013 #6] SUME
没有看起来那么难,是个水题。
我们先考虑
我们有:
于是,
这样,我们就只用三个式子推出来了
同理,对于
当
保证对于任意输入数据,都存在且仅存在一个满足条件的正整数序列
A 。
如果
具体实现可看下面代码:
#include <cstdio>
int s[1005][1005];
int main() {
int n;
scanf("%d", &n);
if (n == 2) {puts("1 1"); return 0;}
for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) scanf("%d", &s[i][j]);
for (int i = 0; i < n; ++i) {
int othera, otherb;
if (i) {
othera = 0;
if (i == 1) otherb = 2;
else otherb = 1;
} else othera = 1, otherb = 2;
printf("%d ", (s[i][othera] + s[i][otherb] - s[othera][otherb]) / 2);
}
}
时间复杂度:处理中的循环只需要循环
空间复杂度:需要一个二维数组存储