Codeforces_711_B
http://codeforces.com/problemset/problem/711/B
比较简单,过程有点繁琐,先找一行包含那个0的行,得到和,以此填出0位置的值,然后判断这个矩阵是否符合条件。
要注意的是,n=1的情况,数据超了int,结果不为负。
#include<iostream>
#include<cstdio>
using namespace std;
long long a[][];
int main()
{
int n,x,y;
cin >> n;
for(int i = ;i <= n;i++)
{
for(int j = ;j <= n;j++)
{
cin >> a[i][j];
if(!a[i][j])
{
x = i;
y = j;
}
}
}
if(n == )
{
printf("1\n");
return ;
}
long long sum = ;
for(int i = ;i <= n;i++)
{
if(i != x)
{
for(int j = ;j <= n;j++)
{
sum += a[i][j];
}
break;
}
}
long long now = ;
for(int i = ;i <= n;i++)
{
now += a[x][i];
}
a[x][y] = sum-now;
for(int i = ;i <= n;i++)
{
long long temp1 = ,temp2 = ;
for(int j = ;j <= n;j++)
{
temp1 += a[i][j];
temp2 += a[j][i];
}
if(temp1 != sum || temp2 != sum)
{
cout << - << endl;
return ;
}
}
long long temp1 = ,temp2 = ;
for(int i = ;i <=n;i++)
{
temp1 += a[i][i];
temp2 += a[i][n-i+];
}
if(temp1 != sum || temp2 != sum)
{
cout << - << endl;
return ;
}
if(a[x][y] <= ) cout << - << endl;
else cout << a[x][y] << endl;
return ;
}
Codeforces_711_B的更多相关文章
随机推荐
- Tensorflow内存暴涨问题
1.目前只总结出两条 创建saver实例saver = tf.train.Saver()放在循环外面 不循环初始化变量 sess.run(tf.global_variables_initializer ...
- CF - 高精度 + 贪心
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two foll ...
- python 进程Queue
1.作用:进程之间的数据交互 2.常用方法 """ 对象.put() 作用:放入队列一个数据 对象.get() 作用:取队列一个数据,若队列没有值,则阻塞 对象.empt ...
- .net core webapi搭建(1)
创建一个webapi项目 修改launchSettings.json 将launchSettings.json中的IIS启动删掉.别问我为啥 原因就是IISEXPRESS有时候需要我手动重启.我嫌麻 ...
- nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.报错解决
近期在学springboot,学的时候遇到这个错,网上查了好多,改了不行,后来发现自己的配置类没有加@SpringBootApplication注解 Exception encountered dur ...
- 关于Navicat连接oralcle出现Cannot load OCI DLL 87,126,193 ,ORA-28547等错误
navicat连接oracle数据库报ORA-28547: connection to server failed, probable Oracle Net admin error错误的解决方法 na ...
- .net core 不是开源的么 作为菜 不能贡献源码 只有 欣赏额
step one 去download一份 与前辈在一起
- jade 的 考古
Jade是一款高性能简洁易懂的模板引擎(加上这两个字我想起了发动机,为什么不直接叫发动机呢), Jade是Haml的Javascript实现, 在服务端(NodeJS)及客户端均有支持. haml 是 ...
- 团队项目-Beta冲刺1
博客介绍 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience 这个作业要求在哪里 https://w ...
- C#中Equals和GetHashCode
Equals和GetHashCode Equals每个实现都必须遵循以下约定: 自反性(Reflexive): x.equals(x)必须返回true. 对称性(Symmetric): x.equal ...