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. java中的二进制

    (1)按位与运算 & 1 & 1 = 1, 0 & 1 = 0 51 & 5  即 0011  0011 & 0000  0101 =0000 0001 = 1 ...

  2. C++菱形继承的构造函数

    网上搜了很多,大多是关于菱形虚继承的构造函数应该怎么写,或者就是最简单的,四个类都不带参数的构造函数. 本文旨在记录一下困扰了博主1h的问题,非常浅显,有帮助固然好,如果侮辱谁的智商还见谅,当然无限欢 ...

  3. Chrome开发者工具详解(3):Timeline面板

    Timeline面板 Timeline面板是整个面板里面最复杂的一个面板,涉及的东西比较多.可以利用这个面板来记录和分析网页运行过程中的所有活动行为信息. 你可以充分利用这个面板来分析你的网页的程序性 ...

  4. 2016 ACM/ICPC Asia Regional Shenyang Online

    I:QSC and Master 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5900 题意: 给出n对数keyi,vali表示当前这对数的键值和权值 ...

  5. Windows - 程序猿应该熟记的CMD常用命令

    notepad 计事本 mspaint 画图 iisreset 重启IIS appwiz.cpl 控制面板 inetmgr IIS管理器 eventvwr 事件查看器 mstsc 远程桌面 net s ...

  6. django的Model 模型中常用的字段类型

    常用的字段类型: AutoField:自增长字段,通常不用,如果未在Model中显示指定主键,django会默认建立一个整型的自增长主键字段 BooleanField:布尔型,值为True或False ...

  7. ie textarea不支持maxlength textarea限制长度

    //ie textarea不支持maxlength $('#verify_note').bind('input propertychange', function() { if (this.value ...

  8. Lucene学习总结之五:Lucene段合并(merge)过程分析

    一.段合并过程总论 IndexWriter中与段合并有关的成员变量有: HashSet<SegmentInfo> mergingSegments = new HashSet<Segm ...

  9. Scrapinghub执行spider抓取并显示图片

    序 最近在学习Scrapy的时候发现一个很有意思的网站,可以托管Spider,也可以设置定时抓取的任务,相当方便.于是研究了一下,把其中比较有意思的功能分享一下: 抓取图片并显示在item里: 下面来 ...

  10. symfony配置

    1.获取配置的一些变量 在HttpFoundation/Kernel.php 文件里面有函数 getKernelParameters ()可以获取一些配置变量的数组.有需要可以从那里获取. 2.配置s ...