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. POJ 1469 ZOJ1140 二分匹配裸题

    很裸,左点阵n,右点阵m 问最大匹配是否为n #include <cstdio> #include <cstring> #include <vector> usin ...

  2. Android应用程序启动过程源代码分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6689748 前文简要介绍了Android应用程 ...

  3. java.util.concurrent.ExecutionException

    java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com ...

  4. ASP.NET内核几大对象、ASP.NET核心知识(7)--转载

    本文的学习流程是这样安排的. 一个简单的GDI小案例 1.说明 如果你想思考如何生成验证码,那么您第一个要解决的问题,一定是.NET动态生成图片问题. //GDI:.Net程序中进行绘图的一些类. 2 ...

  5. C# using垃圾回收详解

    简介 定义一个范围,将在此范围之外释放一个或多个对象. 语法 using (Font font1 = new Font("Arial", 10.0f)) { } C# 语言参考 主 ...

  6. 简单实用的HTML代码

    简单实用的HTML代码 一.HTML各种命令的代码: 1.文本标签(命令) <pre></pre> 创建预格式化文本 <h1></h1> 创建最大的标题 ...

  7. C++重难点知识

    1.顶层const和底层const const int a=10; int b=5; const int *p1=&a; int (*const)p2=&b; p1是顶层const,表 ...

  8. [TYVJ] P1010 笨小猴

    笨小猴 背景 Background NOIP2008复赛提高组第一题   描述 Description 笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼.但是他找到了一种方法,经试验证明,用这种 ...

  9. java中Timer计时器使用

    1.新建计时器Timer对象 2.给计时器安排任务,schedule方法 3.取消计时器中分配的任务,purge方法 4.终止计时器,cancel方法 注意:如果计时器已经终止,还要给计时器安排任务, ...

  10. C# json Helper

    using System; using System.Collections.Generic; using System.Data; using System.Text; namespace Comm ...