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 ...
随机推荐
- xv6的启动过程
bootloader 1. bootasm.S : start32 2. bootmain.c : bootmain kernel 3. main.c : main 4. proc.c : useri ...
- sed使用案例
简介: sed是一种流编辑器,它是文本处理中非常重要的工具,能够完美的配合正则表达式使用,功能不同凡响.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用 ...
- 剑指offer第40题
package com.yan.offer; /** * 题目描述: * * 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. * * @author Ya ...
- 5)添加一个tab
1)还是按照(4)的代码:2) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ ...
- android studio使用JDBC访问mysql数据库(Kotlin方法)
工具:mysql-connector-java-5.1.48.jar,mysql version 5.6.19,android studio内置模拟器 1.connection import java ...
- java笔记-手写
- eclipse启动tomcat出现8080,8009,8005端口被占用的问题
有时候我们在eclipse中启动项目时,Tomcat服务器会报错,显示8080.8009.8005这几个端口被占用,此时你用debug启动项目时会发现不管用,console控制台什么信息也没有,此时产 ...
- LeetCode——623.在二叉树中增加一行
给定一个二叉树,根节点为第1层,深度为 1.在其第 d 层追加一行值为 v 的节点. 添加规则:给定一个深度值 d (正整数),针对深度为 d-1 层的每一非空节点 N,为 N 创建两个值为 v 的左 ...
- DNS服务器搭建与配置
DNS服务器搭建与配置目录 1.DNS查询方式 2.DNS服务器类型 3.DNS主要配置文件组 4.name.conf文件配置介绍 5.DNS的资源记录格式 6.DNS服务器和客户端配置 7.简单搭建 ...
- Java之同步方法处理实现Runnable接口的线程安全问题
/** * 使用同步方法解决实现Runnable接口的线程安全问题 * * * 关于同步方法的总结: * 1. 同步方法仍然涉及到同步监视器,只是不需要我们显式的声明. * 2. 非静态的同步方法,同 ...