In a two dimensional array of integers of size 2×n2 \times n2×n, is it possible to rearrange integers so that the sum of two adjacent elements (which are adjacent in a common row or a common column) is never divisible by three?

Input

The input has several test cases and the first line contains an integer t(1≤t≤200)t (1 \le t \le 200)t(1≤t≤200) which is the number of test cases.

In each case, the first line contains an integers n(1≤n≤10000)n (1 \le n \le 10000)n(1≤n≤10000) indicating the number of columns in the array. The second line contains the elements of the array in the first row separated by single spaces. The third line contains the elements of the array in the second row separated by single spaces. The elements will be positive integers less then 100000010000001000000.

Output

For each test case, output “YES” in a single line if any valid rearrangement exists, or “NO” if not.

样例输入

6
3
3 6 9
1 4 7
3
3 6 9
1 3 8
5
1 2 3 4 5
6 7 8 9 10
10
1 1 1 1 1 1 1 1 1 1
2 3 2 3 2 3 2 3 2 3
2
3 1
2 3
2
3 1
1 2

样例输出

YES
NO
YES
YES
YES
NO
一个大水题嘤嘤嘤
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int s[]={};
int main()
{
ios::sync_with_stdio(false);
int i,m,n;
int T;
cin>>T;
while(T--)
{
bool flag=;
int a=,b=,c=;
cin>>n;
for(i=;i<=*n;i++)
{
cin>>m;
s[i]=m%;
if(s[i]==) a++;
else if(s[i]==) b++;
else if(s[i]==) c++;
}
if(a>n) flag=;
else if(a==n) flag=;
else if(a<n){
if(b==||c==) flag=;
else if(a<=) flag=;
else if(a==){
if(b%==&&c%==) flag=;
else flag=;
}
else flag=;
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}

首先对三取模这是最先想到的

然后对a在各个情况下讨论

当a大于n 肯定是不可能的,因为这样两个0一定会相遇

当a大于n一定可以,交叉嘛

当a小于n

有b和c有只要有一个为0,一定可以

然后是n小于等于1 一定不行

接下来n大于1:

耗费了两个小时啊啊啊

首先这肯定只能找规律,跟数量有关吗,很明显没有关系

那应该跟奇数还是偶数有关

当n奇数我发现其他数一定为一奇一偶,然后一定可以;

于是我就想当n为偶数的时候,然后我就拿2当例子,做了一大堆实验,WA了好多发;

后来才知道2是一个特殊情况,我不能就通过2来断定偶数都是这个规律

Rearrangement的更多相关文章

  1. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  2. HDU 5933 ArcSoft's Office Rearrangement 【模拟】(2016年中国大学生程序设计竞赛(杭州))

    ArcSoft's Office Rearrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  3. HDU 4611Balls Rearrangement(思维)

    Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  4. Balls Rearrangement(HDU)

    Problem Description Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and numbers the ...

  5. hdu4611 Balls Rearrangement

    Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) ...

  6. 2013 多校联合 2 A Balls Rearrangement (hdu 4611)

    Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  7. POJ 1636 Prison rearrangement DFS+0/1背包

    题目链接: id=1636">POJ 1636 Prison rearrangement Prison rearrangement Time Limit: 3000MS   Memor ...

  8. Rearrangement inequality

    摘抄自:  https://en.wikipedia.org/wiki/Rearrangement_inequality#Proof In mathematics, the rearrangement ...

  9. HDU 4611 Balls Rearrangement 数学

    Balls Rearrangement 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4611 Description Bob has N balls ...

  10. HDU 4611 Balls Rearrangement(2013多校2 1001题)

    Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

随机推荐

  1. 使用html画爱心

    <!DOCTYPE html"> <html> <head> <meta http-equiv="Content-Type" c ...

  2. 64bit win7+VS2013+opencv2.4.9配置

    我的配置是opencv2.4.9与VS2013,在win7 64bit下. 从opencv官网(http://opencv.org/downloads.html),下载安装文件,然后双击安装包,类似于 ...

  3. 随机森林RF

    bagging 随机森林顾名思义,是用随机的方式建立一个森林,森林里面有很多的决策树组成,随机森林的每一棵决策树之间是没有关联的.在得到森林之后,当有一个新的输 入样本进入的时候,就让森林中的每一棵决 ...

  4. 直击JDD | 王振辉:技术是驱动物流革新的第一要素

    "从物流基础设施的大规模智能迭代到产业供应链的数字化升级,物流行业从大而重变得'举重若轻',技术是驱动物流革新的第一要素."11月19日,京东物流集团CEO王振辉在2019京东全球 ...

  5. springMVC源码阅读-通过画图理解一个请求生命周期(十二)

  6. Linux--shell 计算时间差

    参考:https://www.cnblogs.com/leixingzhi7/p/6281675.html starttime=`date +'%Y-%m-%d %H:%M:%S'` #执行程序 en ...

  7. JavaScript学习总结(三)

    在学习完了基本的内容之后,我们来学习一下JavaScript中的对象部分以及如何自定义对象的问题. String对象 创建字符串的方式共有两种: 方式1:new String("内容&quo ...

  8. 3.react 基础 - JSX 语法

    1.最基础的 JSX 语法 普通javaScript中 引入 标签 let html = '<h1>hello</h1>'; jsx语法 let JSX_html = < ...

  9. Springboot JpaRepository findOne() 方法报错

    用的是springboot2.0,然后XXXRepository.findOne各种报错,各种不行,上网搜都说改回springboot1.5就好了. 这哪行,直接用XXXRepository.find ...

  10. mysql my.ini 性能调优

    MYSQL服务器my.cnf配置文档详解 硬件:内存16G [client] port = 3306 socket = /data/3306/mysql.sock [mysql] no-auto-re ...