Rearrangement
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的更多相关文章
- 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 ...
- HDU 5933 ArcSoft's Office Rearrangement 【模拟】(2016年中国大学生程序设计竞赛(杭州))
ArcSoft's Office Rearrangement Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 4611Balls Rearrangement(思维)
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- Balls Rearrangement(HDU)
Problem Description Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and numbers the ...
- hdu4611 Balls Rearrangement
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) ...
- 2013 多校联合 2 A Balls Rearrangement (hdu 4611)
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- POJ 1636 Prison rearrangement DFS+0/1背包
题目链接: id=1636">POJ 1636 Prison rearrangement Prison rearrangement Time Limit: 3000MS Memor ...
- Rearrangement inequality
摘抄自: https://en.wikipedia.org/wiki/Rearrangement_inequality#Proof In mathematics, the rearrangement ...
- HDU 4611 Balls Rearrangement 数学
Balls Rearrangement 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4611 Description Bob has N balls ...
- HDU 4611 Balls Rearrangement(2013多校2 1001题)
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
随机推荐
- 64bit win7+VS2013+opencv2.4.9配置
我的配置是opencv2.4.9与VS2013,在win7 64bit下. 从opencv官网(http://opencv.org/downloads.html),下载安装文件,然后双击安装包,类似于 ...
- JavaScript 之 Function
JavaScript function 语句定义和用法: function 语句用于声明一个函数. 函数声明后,我们可以在需要的时候调用. 在 JavaScript 中,函数是对象,函数也有属性和方法 ...
- Java学生管理系统(IO版)
图解: cade: student.java /* * 这是我的学生类 */ public class Student { //学号 private String id; //姓名 private S ...
- 干货 | 京东云托管Kubernetes集成镜像仓库并部署原生DashBoard
在上一篇"Cloud Native 实操系列"文章中,我们为大家介绍了如何通过京东云原生容器实现Eureka的部署(
- cmd定时自动弹窗命令
at 17:00 /e:m,t,w,th,f,s,su msg * 弹窗文字
- [Python]h5py/__init__.py:36:
个人博客地址:https://www.bearoom.xyz/2019/08/24/python-devolop-env-hdf5-problem/ 安装tensorflow之后,在导入tensorf ...
- 24.docker 部署 wordPress
1. 拉取远程 mysql 和 wordpress 镜像 并 启动起来 使用 docker pull mysql:5.7.27 docker pull wordpress 2. 创建mysql 的 c ...
- svg用例
圆<circle cx="x" cy="y" r="r" style="stroke:black;fill:none&quo ...
- winEdt打开tex文件报错解决方法
写论文真的是不断遇到各种困难啊,这个Latex软件就很多,好不容易中个A1区的文章,期刊说更新了新的模板就下载了,忽然发现打开有reading error,看不到一点内容,神奇的是竟然可以运行.这样的 ...
- OutOfMemoryError异常
1.Java堆溢出 Java堆用于存储对象实例,只要不断地创建对象,并且保证GC Roots到对象之间有可达路径来避免垃圾回收机制清除这些对象,就会在对象数量达到最大堆的容量限制后产生内存溢出异常. ...