CodeForces - 711B Chris and Magic Square
CodeForces - 711B Chris and Magic Square
#include<iostream>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll r[505],c[505],angle[3];
ll a[505][505];
int main(void)
{int n;cin>>n;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>a[i][j];if(n==1){cout<<1<<endl;return 0;}int u,v;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){r[i]+=a[i][j];c[i]+=a[j][i];if(a[i][j]==0){u=i;v=j;}if(i==j) angle[1]+=a[i][j];if((i+j)==(n+1)) angle[2]+=a[i][j];}int flag=1;ll R; for(int i=1;i<=n;i++){if(i==u) continue;if(flag){R=r[i];flag=0;continue;}if(r[i]!=R){cout<<-1<<endl;return 0;}}ll C;flag=1;for(int i=1;i<=n;i++){if(i==v) continue;if(flag){C=c[i];flag=0;continue;}if(c[i]!=C){cout<<-1<<endl;return 0; }}if(R!=C){cout<<-1<<endl;return 0;}if(u!=v&&(u+v)!=(n+1)){if(angle[1]==angle[2]&&angle[2]==R&&r[u]==c[v]&&R-r[u]>=1&&R-r[u]<=INF){cout<<R-r[u]<<endl;return 0;}else{cout<<-1<<endl;return 0;}}if(u==v&&(u+v)!=(n+1)){if(r[u]==c[v]&&angle[1]+R-r[u]==angle[2]&&angle[2]==R&&R-r[u]>=1&&R-r[u]<=INF){cout<<R-r[u]<<endl;return 0;}else{cout<<-1<<endl;return 0;}}if(u!=v&&(u+v)==(n+1)){if(r[u]==c[v]&&angle[2]+R-r[u]==angle[1]&&angle[1]==R&&R-r[u]>=1&&R-r[u]<=INF){cout<<R-r[u]<<endl;return 0;}else {cout<<-1<<endl;return 0;}}if(u==v&&(u+v)==(n+1)){if(r[u]==c[v]&&angle[2]==angle[1]&&angle[1]==c[v]&&R-r[u]>=1&&R-r[u]<=INF){cout<<R-r[u]<<endl;return 0;}else{cout<<-1<<endl;return 0;}}return 0;
}
CodeForces - 711B Chris and Magic Square相关推荐
- codeforces 711B - Chris and Magic Square(矩阵0位置填数)
题目链接:http://codeforces.com/problemset/problem/711/B 题目大意: 输入 n ,输入 n*n 的矩阵,有一个占位 0 , 求得将 0 位置换成其他的整数 ...
- Codeforces Round #369 (Div. 2) B. Chris and Magic Square【数学,模拟】
B. Chris and Magic Square time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- cf369 B Chris and Magic Square
B. Chris and Magic Square time limit per test2 seconds memory limit per test256 megabytes inputstand ...
- B. Chris and Magic Square
B. Chris and Magic Square time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Chris and Magic Square
Chris and Magic Square ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There ...
- Chris and Magic Square CodeForces - 711B
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid o ...
- 文章标题 Chris and Magic Square
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid o ...
- 【codeforces 711B】Chris and Magic Square
[题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...
- Codeforces 711B- Chris and Magic Square
B. Chris and Magic Square time limit per test 2 seconds memory limit per test 256 megabytes input st ...
最新文章
- 韩国一周新增千例确诊,想用 AI 定位出咳嗽的人
- tensorflow随笔-简单CNN(卷积深度神经网络结构)
- java子类和父类实例_java中父类与子类之间的转换示例
- Swift - 触摸事件(点击,移动,抬起等)说明及用例
- CCF	2017-3-2 学生排队
- Python爬虫入门并不难,甚至入门也很简单
- Godot 导出 Android apk
- 《Redis视频教程》(p2)
- eclipse工具按键翻译
- 关于breadcrumb面包屑
- linux挂载40t硬盘,Centos支持40T磁盘阵列MD1200
- FFmpeg基础: 视频裁剪
- 京东移动端首页-流式布局
- 华为p10android版本,华为P10系列什么时候升级安卓8.0?官方给出答案
- CentOS7 查询版本/CPU/内存/硬盘容量等命令
- 《UNIX编程艺术》精彩语录
- JSON解析合集:你再也不用怕JSON解析了!!!
- 日本研制超音速小飞机或达音速2倍
- 6.2 网络钓鱼攻击
- iMeta | 第1卷第4期来自8个国家的20篇文章正式发布(2022.12)
热门文章
- 全志Linux下载工具,全志 Allwinner A20 机顶盒刷入原生 Debian
- R绘图笔记 | 小提琴图与漂亮的云雨图绘制
- c 调用python类_C调用Python解析Excel
- meterpreter会话渗透利用常用的32个命令归纳小结
- 惠普136wm显示无法连接服务器,136w打印机时连接无线时显示连接失败
- 谈谈智能穿戴设备最火主控芯片NRF51422/NRF51822的开发感受
- 美狐美颜SDK趣拍功能的算法代码解析
- 3RA生态之定时器输出PWM
- Arduino工程源码分析
- 为什么安监控需要公网ip_视频监控系统分布式集中监控对宽带有何要求?带宽得多大?...