Description

2个n\(\times\)m矩阵,保证同一个矩阵中元素两两不同。问能否通过若干次交换两行或交换两列把第一个矩阵变成第二个。

Input

第一行正整数T(1≤T≤10)表示数据组数.

每组数据包括:第一行nm(1≤n,m≤1000)2个n行m列的整数矩阵,

元素绝对值均在10^6以内

Output

每组数据输出“TAK”/“NIE”表示能/不能.

Sample Input

2

4 3

1 2 3

4 5 6

7 8 9

10 11 12

11 10 12

8 7 9

5 4 6

2 1 3

2 2

1 2

3 4

5 6

7 8

Sample Output

TAK

NIE


这题随便乱搞即可

找到第一个矩阵中的每一行应该对应第二个矩阵的某一行,然后求出置换序列,最后判断每一行的置换序列是否一样即可

然后找到对应的行数我就是sort+hash……反正巨蠢……

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
const int N=1e3,p=1e9+7,digit=233,limit=1e6;
int A[N+10][N+10],B[N+10][N+10],_A[N+10][N+10],_B[N+10][N+10];
int cnt[(limit<<1)+10],pol[N+10];
struct S1{
int hash,ID;
void insert(int a,int b){hash=a,ID=b;}
bool operator <(const S1 &x)const{return hash<x.hash;}
}HA[N+10],HB[N+10];
int n,m;
int Hash(int *a){
int res=0;
for (int i=1;i<=m;i++) res=(1ll*res*digit+a[i])%p;
return res;
}
void work(){
n=read(),m=read();
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++) A[i][j]=_A[i][j]=read()+limit;
sort(_A[i]+1,_A[i]+1+m);
HA[i].insert(Hash(_A[i]),i);
}
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++) B[i][j]=_B[i][j]=read()+limit;
sort(_B[i]+1,_B[i]+1+m);
HB[i].insert(Hash(_B[i]),i);
}
sort(HA+1,HA+1+n),sort(HB+1,HB+1+n);
for (int i=1;i<=n;i++) if (HA[i].hash!=HB[i].hash){printf("NIE\n");return;}
for (int i=1;i<=m;i++) cnt[B[HB[1].ID][i]]=i;
for (int i=1;i<=m;i++) pol[i]=cnt[A[HA[1].ID][i]];
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
if (A[HA[i].ID][j]!=B[HB[i].ID][pol[j]]){printf("NIE\n");return;}
printf("TAK\n");
}
int main(){
for (int Data=read();Data;Data--) work();
return 0;
}

[POI2009]Tab的更多相关文章

  1. BZOJ 1142: [POI2009]Tab

    1142: [POI2009]Tab Time Limit: 40 Sec  Memory Limit: 162 MBSubmit: 213  Solved: 80[Submit][Status][D ...

  2. bzoj 1142 [POI2009]Tab 最小表示

    [POI2009]Tab Time Limit: 40 Sec  Memory Limit: 162 MBSubmit: 373  Solved: 167[Submit][Status][Discus ...

  3. bzoj1142:[POI2009]Tab

    传送门 考虑每次交换都不会改变每个数所在的行和列(不是指编号,而是指和它在同一行或者同一列的数不会发生变化) 由于每个数互不相同,所以记录下每个数所在的行和列,暴力判断就好了 代码: #include ...

  4. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  5. android 使用Tabhost 发生could not create tab content because could not find view with id 错误

    使用Tabhost的时候经常报:could not create tab content because could not find view with id 错误. 总结一下发生错误的原因,一般的 ...

  6. 谈谈一些有趣的CSS题目(八)-- 纯CSS的导航栏Tab切换方案

    开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...

  7. GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1)

    GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1) 前言: 无意打开GooglePlay app来着,然后发现首页用了揭示效果,连起来用着感觉还不错. 不清楚 ...

  8. 通过easyui tab添加的子页面JS脚本必须放在body才生效

    通过easyui tab添加的子页面JS脚本必须放在body才生效 可通过Chrome查看元素时,head标签是否含有你自己写的JS代码

  9. jQuery的DOM操作实例(1)——选项卡&&Tab切换

    一.原生JavaScript编写tab切换 二.jQuery编写tab切换 在用jQuery编写选项卡过程中,重要的事搞清楚 .eq() 和 .index() 的使用方法. .eq()是jQuery遍 ...

随机推荐

  1. 【转】面向切面编程-AOP,挺有用的

    原文:http://blog.csdn.net/yangzhihello/article/details/40377399 下面的代码有点问题, ins[methodName] = function( ...

  2. [Javascript] Use JavaScript's for-in Loop on Objects with Prototypes

    Loops can behave differently when objects have chained prototype objects. Let's see the difference w ...

  3. iOS中3种正则表达式的使用

    1.利用NSPredicate(谓词)匹配 例如匹配有效邮箱: ? 1 2 3 4 NSString *email = @“nijino_saki@163.com”:  NSString *regex ...

  4. C#结构类型图

    C#结构类型图     分类: C#

  5. vsCode 常用快捷键(mac 版)

    光标多行显示: commond+Alt+topArrow/downArrow 查找:commond+F 查找并按顺序切换下一个:commond+G 跳转到某一行: ctrl+G 输入行号跳转 跳转到某 ...

  6. Codeforces Little Dima and Equation 数学题解

    B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...

  7. SpringMVC_基本配置 --跟海涛学SpringMVC(和自己在项目中的实际使用的对比)

    ☆依赖jar包: 1.Spring框架jar 包: 为了简单,将spring-framework-3.1.1.RELEASE-with-docs.zip/dist/下的所有jar包拷贝到项目的WEB- ...

  8. MVC优缺点

    1.通过把项目分成model view和controller,使得复杂项目更加容易维护. 2.没有使用view state和服务器表单控件,可以更方便的控制应用程序的行为 3.应用程序通过contro ...

  9. tunctl和虚拟网卡

    1 tun/tap驱动 1.1 网卡驱动 同tcp/ip协议栈打交道,接受和发送数据包 1.2 字符驱动 内核和用户态通过字符设备交换数据包. 2 tun虚拟网卡的创建 tunctl -t tun0 ...

  10. 内部消息 微软中国云计算 内測Azure免费账号 赶紧申请 错过不再有

    内部消息 微软中国云计算 顶级内測Azure免费账号 火热申请 过期不再有! 微软MSDN俱乐部  29754721, [一大波Azure免费账号来袭]Windows Azure再次开启示放免费试用账 ...