Is it a fantastic matrix?

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 5   Accepted Submission(s) : 2

Problem Description

Given an n*m matrix, you are asked to judge if it's fantastic. The rule is: firstly, choose min (n, m) numbers from it, meanwhile you should make sure any two numbers you select will not at the same row or same column. Of course, you may have many different
ways to get the numbers. For every way, if the sum of all selected numbers is always same, you may say the matrix is fantastic.

Input

The first line contains an integer T, stands for the number of test cases. (1<=T<=100)

T cases follow, for every case:

The first line contains two integers n and m. (1 <= n, m <= 50)

Then n lines follows, each line contains m integers. Every number in the matrix will between -100000 and 100000.

Output

For every case, if it is a fantastic matrix, output “YES” in one line, otherwise output “NO”.

Sample Input

3
2 2
1 3
2 4
2 3
1 1 1
1 1 1
2 1
2
3

Sample Output

YES
YES
NO

Source

hujie 测试专用(2)

这个题当初就思考了很久 可惜还是没有考虑 周全

当n<m的时候 每一行都必须相同
1 1 1 1
2 2 2 2
3 3 3 3
如果不相同显然反例可证明
n>m 时候同理


当时只考虑了n==m的情况
得到了等式 a[k][jk]+a[t][jt]=a[k][jt]+a[t][jk]; (利用行列式的方式描述一个元素的位置 a[1][j1])

当k=1 ,jk=1 的时候  a[1][1]+a[t][jt]=a[1][jt]+a[t][1];
同时可以写出另外3个
a[k][jk]+a[1][1]=a[k][1]+a[1][jk]
a[1][jk]+a[t][1]=a[1][1]+a[t][jk]
a[k][1]+a[1][jt]=a[k][jt]+a[1][1]
累加起来即为 a[k][jk]+a[t][jt]=a[k][jt]+a[t][jk]

所以我们只需判断 a[x][y]+a[1][1]==a[x][1]+a[1][y]即可
代码如下:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
using namespace std;
int MAP[60][60];
int main()
{
int T;
cin>>T;
while(T--)
{
int OK=1;
int m,n;
cin>>n>>m;
if(n>m) //懒得写
if(n<m) //懒得写
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&MAP[i][j]);
if(n==1||m==1) { printf("NO\n");continue;}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(MAP[i][j]+MAP[1][1]!=MAP[1][j]+MAP[i][1]) OK=0;
if(OK) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}

【考虑周全+数学变形】【11月赛】Is it a fantastic matrix?的更多相关文章

  1. [LOJ 6249]「CodePlus 2017 11 月赛」汀博尔

    Description 有 n 棵树,初始时每棵树的高度为 H_i,第 i 棵树每月都会长高 A_i.现在有个木料长度总量为 S 的订单,客户要求每块木料的长度不能小于 L,而且木料必须是整棵树(即不 ...

  2. [LOJ 6248]「CodePlus 2017 11 月赛」晨跑

    Description “无体育,不清华”.“每天锻炼一小时,健康工作五十年,幸福生活一辈子” 在清华,体育运动绝对是同学们生活中不可或缺的一部分.为了响应学校的号召,模范好学生王队长决定坚持晨跑.不 ...

  3. [CodePlus 2017 11月赛&洛谷P4058]木材 题解(二分答案)

    [CodePlus 2017 11月赛&洛谷P4058]木材 Description 有 n棵树,初始时每棵树的高度为 Hi ,第 i棵树每月都会长高 Ai.现在有个木料长度总量为 S的订单, ...

  4. [CodePlus 2017 11月赛]晨跑 题解(辗转相除法求GCD)

    [CodePlus 2017 11月赛]晨跑 Description "无体育,不清华"."每天锻炼一小时,健康工作五十年,幸福生活一辈子".在清华,体育运动绝 ...

  5. [BZOJ5109][LOJ #6252][P4061][CodePlus 2017 11月赛]大吉大利,今晚吃鸡!(最短路+拓扑排序+传递闭包+map+bitset(hash+压位))

    5109: [CodePlus 2017]大吉大利,晚上吃鸡! Time Limit: 30 Sec  Memory Limit: 1024 MBSubmit: 107  Solved: 57[Sub ...

  6. loj #6250. 「CodePlus 2017 11 月赛」找爸爸

    #6250. 「CodePlus 2017 11 月赛」找爸爸 题目描述 小 A 最近一直在找自己的爸爸,用什么办法呢,就是 DNA 比对. 小 A 有一套自己的 DNA 序列比较方法,其最终目标是最 ...

  7. FOJ 2013 11 月赛

    这套题目还是比较吊的,由于我的沙茶,还是很多没有做出来- -! C:逆序数 D:呵呵 A:妈蛋,自己精度没弄好,想到之前GCC的要加eps,就WA了几次后交Visual C++过了!C(n,m)p^m ...

  8. 「CodePlus 2017 11 月赛」Yazid 的新生舞会(树状数组/线段树)

    学习了新姿势..(一直看不懂大爷的代码卡了好久T T 首先数字范围那么小可以考虑枚举众数来计算答案,设当前枚举到$x$,$s_i$为前$i$个数中$x$的出现次数,则满足$2*s_r-r > 2 ...

  9. 「CodePlus 2017 11 月赛」大吉大利,晚上吃鸡!(dij+bitset)

    从S出发跑dij,从T出发跑dij,顺便最短路计数. 令$F(x)$为$S$到$T$最短路经过$x$的方案数,显然这个是可以用$S$到$x$的方案数乘$T$到$x$的方案数来得到. 然后第一个条件就变 ...

随机推荐

  1. poj3358数论(欧拉定理)

    http://poj.org/problem?id=3358 (初始状态为分数形式)小数点进制转换原理:n / m ; n /= gcd( n , m ) ; m/= gcd( n , m ) ; n ...

  2. 仿桌面通知pnotify插件

    在做网站的时候,alert弹出框是非常常见的情形.但是,有些情况下,弹框对用户来说是并不友好的.调研了几个其他的提示插件了,发现pnotify比较好用,可配置性也高. 使用示例: <!DOCTY ...

  3. bower安装使用以及git安装

    bower需要:node 和 git node安装包下载:http://blog.csdn.net/myan/article/details/2028545 Git安装: 选择第二项:Use Git ...

  4. H5移动端性能优化

    概述 1. PC优化手段在Mobile侧同样适用 2. 在Mobile侧我们提出三秒种渲染完成首屏指标 3. 基于第二点,首屏加载3秒完成或使用Loading 4. 基于联通3G网络平均338KB/s ...

  5. SQL中的delete和TRUNCATE的用法

    TRUNCATE TABLE 表名 删除表中的所有行,而不记录单个行删除操作. 语法 TRUNCATE TABLE name 参数 name 是要截断的表的名称或要删除其全部行的表的名称. 注释 TR ...

  6. Xcode的代码片段快捷方式-Code Snippet Library(代码片段库)

    最近换了新电脑,装上Xcode敲代码发现很多以前攒的Code Snippet忘记备份了,总结了一下Code Snippet的设置方法,且行且添加,慢慢积累吧. 如下图:   Title - Code ...

  7. IOS 实现QQ好友分组展开关闭功能

    贴出核心代码  主要讲一下思路. - (void)nameBtnClick:(myButton *)sender { //获取当前点击的分组对应的section self.clickIndex = s ...

  8. git commit的--amend选项

    git commit --amend常常用来修改某个branch上最顶端的commit,大多数情况下,这个命令给人的感觉是用新的commit替换了原来的commit.git commit --amen ...

  9. MongoDB监控一 mongostat

    mongostat命令                                                               mongostat可以提供mongod和mongos ...

  10. 关于bootstrap列偏移的两种方式

    第一种方式: <div class="col-md-2 col-md-offset-9"> <input type="text" class= ...