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 ...
随机推荐
- 2019.9.30极限测试 04.JAVA语言课堂测试试卷-极限测试
题目存储在上传的文件当中. 代码实现 Subway 类: package ClassroomTest; public class Subway { private String railway; pr ...
- 最短路问题-- Dijkstra Choose the best route
Choose the best route Problem Description One day , Kiki wants to visit one of her friends. As she i ...
- 移动端H5开发遇到的问题及解决方法
本篇文章给大家带来的内容是关于移动端H5开发遇到的问题及解决方法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 微信分享签名错误invalid signature vue单页应用hi ...
- 1)warning LNK4233
名称 test.exe 包含非 ASCII 字符,在具有除 936 以外的 ANSI 代码页的系统上可能不能加载 DLL 名称 练习动态库.dll 包含非 ASCII 字符,如果系统没有与用于链接此 ...
- 指针数组的初始化和遍历,并且通过for循环方式、函数传参方式进行指针数组的遍历
/************************************************************************* > File Name: message.c ...
- sync实现windows与nginx主机端文件同步(参考文档)
资源 Rsync官网:http://rsync.samba.org/ 简介 Rsync(remote sync)是类unix系统下的远程(LAN/WAN)数据镜像备份工具.可以实现Linux与linu ...
- C++对象数组与对象指针
(一)对象数组 将具有相同类类型的对象有序地集合在一起便构成了对象数组,以一维对象数组为例,其定义形式为: 类名 对象数组名[]; Point points[100]; 关于对象数组的几点说明: (1 ...
- 如何修改Jquery Mobile 设置默认选项
以下的默认配置可以通过$.mobile对象重新配置自定义命名空间s (字符, 默认: ""): 在jQuery Mobile中,甚至可以自定义象HTML5中的data-attrib ...
- 京东云数据库 RDS助力企业便捷运维
iPhone6发布那年,京东在国贸等商圈送货最快速度数分钟,包括从下单到送达.这是一个极端的富含营销因素例子.即便如此,常态来看,隔天到货的这种业务模式,也是基于同样的支撑:营销业务.物流业务,大数据 ...
- Spring--Spring 注入
Spring 提供了三种主要的装配机制: 在 XML 中进行显式配置 在 Java 中进行显式配置 隐式的 bean 发现机制和自动装配 Spring 从两个角度来实现自动化装配: 组件扫描:Spri ...