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. 使用AJAX(阿贾克斯)创建级联菜单

    1. html页面 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  2. [SDOI2016]游戏(树剖+李超树)

    趁着我把李超树忘个一干二净的时候来复习一下吧,毕竟马上NOI了. 题解:看着那个dis就很不爽,直接把它转换成深度问题,然后一条直线x->y,假设其lca为z,可以拆分成x->z和z-&g ...

  3. page-break-before和page-break-after 实现分页打印

    page-break-before和page-break-after CSS属性并不会修改网页在屏幕上的显示,这两个属性是用来控制文件的打印方式.每个打印属性都可以设定4种设定值:auto.alway ...

  4. 哈希表hashTable的Java设计

    1:哈希表的概念 2:设计原理 3:哈希表的Java设计

  5. iris数据集预测

    iris数据集预测(对比随机森林和逻辑回归算法) 随机森林 library(randomForest) #挑选响应变量 index <- subset(iris,Species != " ...

  6. Go语言-并发模式-goroutine池实例(work)

    介绍 使用无缓冲的通道来创建一个 goroutine 池,这些 goroutine 执行并控制一组工作,让其并发执行.在这种情况下,使用无缓冲的通道要比随意指定一个缓冲区大小的有缓冲的通道好,因为这个 ...

  7. P1618 三连击(升级版)

    题解: #include<stdio.h>int main(){ int A,B,C; scanf("%d %d %d",&A,&B,&C);  ...

  8. String,StringBuffer与StringBuilder的区别与选择

    三者的区别 String:不可变类,一旦一个对象被建立的时候,包含在这个对象中的字符串序列是不可变的,直到这个对象被销毁.StringBuffer:可变字符序列的字符串.当其对象被创建的时候,可以用a ...

  9. PAT Advanced 1008 Elevator (20) [数学问题-简单数学]

    题目 The highest building in our city has only one elevator. A request list is made up with N positive ...

  10. flask汇总

    flask框架 蓝图 随着flask程序越来越复杂,我们需要对程序进行模块化的处理,之前学习过python的模块化管理,于是针对一个简单的flask程序进行模块化处理 Blueprint概念 简单来说 ...