Gym 101611G
一个正方形肯定只能要么,顺时针要么逆时针转动,因为先顺时针,后逆时针或者相反,是没有意义的。假设第一块正方向顺时针a1次,第二块a2次。。。以此类推,可以得到方程组,横向全部为零,纵向全部为零。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<map>
//#include<regex>
#include<cstdio>
#include <iomanip>
#pragma GCC optimize(2)
#define up(i,a,b) for(int i=a;i<b;i++)
#define dw(i,a,b) for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
char ch = getchar(); ll x = 0, f = 1;
while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
typedef pair<int, int> pir;
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lrt root<<1
#define rrt root<<1|1
const int N = 550;
ll r[N][N], c[N][N];
int n, m;
int main()
{
n = read(), m = read();
up(i, 0, n)
{
up(j, 0, m)
{
ll x, y; x = read(), y = read();
r[i][j] = x; c[i][j] = y;
}
}
ll sum = 0;
bool flag = 0;
up(i, 0, n)
{
up(j, 0, m)
{
sum += c[i][j];
}
sum == 0 ? flag = 0 : flag = 1;
if (flag)break;
}
if (flag) {
printf("No");
}
else {
sum = 0;
up(j, 0, m)
{
up(i, 0, n)
{
sum += r[i][j];
}
sum == 0 ? flag = 0 : flag = 1;
if (flag)break;
}
if (flag)
{
printf("No");
}
else printf("Yes");
}
return 0;
}
橙橙橙