Codeforces Round #627 (Div. 3) A - Yet Another Tetris Problem(逻辑)
题意 :
有n个高度,可以使任一高度加二任意次,问最终n个高度可否相同。
思路:
因为添加的2x1的方块不可旋转,只需考虑所有高度是否为同一奇偶性即可。
#include <bits/stdc++.h>
using namespace std; void solve(){
int n;cin>>n;
int a[n],sum=0; for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) sum+=a[i]&1; if(sum==0||sum==n)cout<<"YES\n";
else cout<<"NO\n";
} int main(){
int t;cin>>t;
while(t--)
solve();
return 0;
}
拓展:
若可以旋转,原数组奇为1,偶为0,看是否同奇偶或0两两相邻即可。
#include <bits/stdc++.h>
using namespace std; void solve(){
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) a[i]&=1; int sum=accumulate(a,a+n,0);
if(sum==0||sum==n){
cout<<"YES\n";
return;
}
for(int i=0;i<n-1;i++){
if(a[i]==0){
if(a[i+1]==1){
cout<<"NO\n";
return;
}
i++;
}
}
cout<<"YES\n";
} int main(){
int t;cin>>t;
while(t--)
solve();
return 0;
}
Codeforces Round #627 (Div. 3) A - Yet Another Tetris Problem(逻辑)的更多相关文章
- Codeforces Round #627 (Div. 3) B - Yet Another Palindrome Problem(逻辑)
题意: 问一个数组中是否存在至少长为3的回文子数组(按下标排列,可不连续). 思路: 找三个相同数或两个不连续的相同数. #include <bits/stdc++.h> using na ...
- Codeforces Round #627 (Div. 3)
1324A - Yet Another Tetris Problem(思维) 题意 给一个数组,每一个数组中的元素大小表示在竖直方向的方块数量,元素相邻怎竖直方向的方块也相邻,类似于俄罗斯方块当底层被 ...
- [每日一题2020.06.07]codeforces Round #627 (Div. 3)
problem A /* * Author: RoccoShi * Time: 2020-06-07 19:37:51 */ #include <bits/stdc++.h> using ...
- Codeforces Round #627 (Div. 3) F - Maximum White Subtree(深度优先搜索)
题意: n 个点 n - 1 条边的树,问每个点所在所有子树中白黑点数目的最大差. 思路: 白点先由下至上汇集,后由上至下分并. #include <bits/stdc++.h> usin ...
- Codeforces Round #627 (Div. 3) E - Sleeping Schedule(递推)
题意: 每天有 h 小时,有一序列 an,每次可以选择 ai 或 ai - 1 小时后睡觉,问从 0 次 0 时开始,最多在 l ~ r 时间段入睡多少次. 思路: 如果此时可达,计算此时可达的时间点 ...
- Codeforces Round #627 (Div. 3) D - Pair of Topics(双指针)
题意: 有长为n的a,b两序列,问满足ai+aj>bi+bj(i<j)的i,j对数. 思路: 移项得:(ai-bi)+(aj-bj)>0,i<j即i!=j,用c序列保存所有ai ...
- Codeforces Round #627 (Div. 3) C - Frog Jumps(逻辑)
题意: 有一个每个单元标明移动方向的长为n的序列,每次移动不能超过距离k,问能够从0移动到n+1的k的最小值. 思路: k=最长连续L序列长度+1. #include <bits/stdc++. ...
- Codeforces Round #410 (Div. 2)C. Mike and gcd problem
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 secon ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合
E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...
随机推荐
- Spring Cloud Gateway 跨域 CORS 配置方式实现
网上找了一堆文章全是说这样写无效 globalcors: cors-configurations: '[/**]': allowCredentials: true allowedOriginPatte ...
- 【Java基础】Java10 新特性
Java10 新特性 局部变量类型推断 局部变量的显示类型声明,常常被认为是不必须的. 场景一:类实例化时.在声明一个变量时,总是习惯了敲打两次变量类型,第一次用于声明变量类型,第二次用于构造器. 场 ...
- Docker Harbor 高可用 1.7.5版本(七)
环境说明: node1 10.10.5.135 仓库 1 node2 10.10.5.136 仓库 2 node3 10.10.5.137 客户端 实验内容: Harbor 可以在两台主机之间相互同步 ...
- Ansible-playbook 安装redis
Ansible-playbook 安装redis 创建目录: ### 创建剧本规范目录: mkdir -p /etc/ansible/roles/redis/{files,templates,vars ...
- Java 在pom.xml中配置build resources, 来防止我们资源导出失败问题(Maven项目)
在pom.xml中配置build, 来防止我们资源导出失败问题 <!--在build中配置resources, 来防止我们资源导出失败问题--> <build> <res ...
- 【Linux】rsync模板配置问题
------------------------------------------------------------------------------------------------- | ...
- [oracle] exp-00091
产生原因: 在数据库的服务器端和客户端字符集不同的情况下,导出(dump)数据库表时,会产生这个错误.虽然产生这个错误,但好像对导入没有影响. 解决办法: 查看服务器端字符集: 打开SQLPLUS,执 ...
- 【Oracle】更改oracle中的用户名称
修改oracle中的用户名,要需要修改oracle基表中的相关内容, 1.查看user#, select user#,name from user$ s where s.name='用户修改前的'; ...
- 【ORA】ORA-01078和LRM-00109 解决方法
今天切换到asm实例的时候,发现是一个空实例,尝试启动实例,结果报错ORA-01078和LRM-00109 SQL> startupORA-01078: failure in processin ...
- linux搭建简单samba服务器
1.安装需要的软体 yum install -y samba samba-client samba-common 2.创建samba需要的本地用户,创建samba服务使用的目录 Linux系统文件的读 ...