Gym 101484 I Matrix Sum
来源:互联网 发布:网络代理可信吗 编辑:程序博客网 时间:2024/05/22 00:39
题意:题目给了一个矩阵
其中
问,给定一个
分析: 这个题的关键就是从
我们用
用
用
则原定义变成了:
即
所以,如果
所以会得到第二个等式:
所以,如果
对于每个
以下是代码。
#include<bits/stdc++.h>using namespace std;#define ull unsigned long long#define ll long long#define lson l,mid,id<<1#define rson mid+1,r,id<<1|1typedef pair<int, int>pii;typedef pair<ll, ll>pll;typedef pair<double, double>pdd;const double eps = 1e-6;const int MAXN = 1005;const int MAXM = 100005;const ll LINF = 0x3f3f3f3f3f3f3f3f;const int INF = 0x3f3f3f3f;const double FINF = 1000000000000000.0;const ll MOD = 1000000007;const double PI = acos(-1);int f[MAXN][MAXN];int row[MAXN], col[MAXN];int main() { memset(col, 0, sizeof(col)); memset(row, 0, sizeof(row)); int n, tot = 0; scanf("%d", &n); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { scanf("%d", &f[i][j]); row[i] += f[i][j]; col[j] += f[i][j]; tot += f[i][j]; } } if (n == 1) { if (f[1][1] == 1 || f[1][1] == 0)goto ans_1; else goto ans_0; } if (tot % (2 * n - 1) != 0)goto ans_0; tot = tot / (2 * n - 1); for (int i = 1; i <= n; ++i) { if ((row[i] - tot) % (n - 1) || row[i] < tot)goto ans_0; if ((col[i] - tot) % (n - 1) || col[i] < tot)goto ans_0; row[i] = (row[i] - tot) / (n - 1); col[i] = (col[i] - tot) / (n - 1); } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { int now = row[i] + col[j] - f[i][j]; if (now != 0 && now != 1)goto ans_0; } } goto ans_1;ans_0: printf("0\n"); return 0;ans_1: printf("1\n"); return 0;}
- Gym 101484 I Matrix Sum
- codeforces Gym 101341 I Matrix God
- Matrix Gym
- Gym 101503I Just Matrix【思维+拓扑排序】好题~
- Codeforces Gym 100339I Sum vs Product 剪枝搜索
- Matrix Sum
- Xor Sum Gym
- Xor Sum Gym
- I - Matrix
- CodeForces Gym 100735I
- Mirrored String I Gym
- Gym 101147.I
- Gym 101164.I
- Gym 101243.I
- Gym 101482. I
- Gym 101623I
- Gym 100499I (数学 模拟)
- Gym 100703I 尺取法
- 网络编程(python)
- apt-get安装软件Unable to locate package错误解决办法
- NYOJ201
- plan(Tag,ToDo/Doing),在路上的思考
- C++ MFC / VS2013 之六 (对话框:创建对话框类和添加控件变量)
- Gym 101484 I Matrix Sum
- python--leetcode654.Maximum Binary Tree
- 队列的实现
- 对继承的考察
- ubuntu16 pytorch 源码编译安装教程
- 优先队列的实现
- 【Linux】虚拟机vmware的安装
- Leetcode-Add Binary
- Asp.Net开发中未整理的资料