D1. Great Vova Wall (Version 1)
链接
[https://codeforces.com/contest/1092/problem/D1]
题意
给你n个位置墙的高度,现在你有2×1 砖块,你可以竖直或者水平放置
问你是否可以使得所有位置高度一样
思路
都在代码里,看了你就恍然大悟了。。。仔细想想
代码
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,h;
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n)){
stack<int> stk;
scanf("%d",&h);
stk.push(h);
for(int i=2;i<=n;i++)
{
scanf("%d",&h);
if(stk.size()&&(h-stk.top())%2==0){//这里很关键,因为对于相差2的倍数,
//肯定是可以填砖使得二者高度相等,相等就可以去掉这两个位置
//因为后面出现的位置总可以填砖使得与二者高度相等,
//比如 554,先变成664,再变成666
//或者338,直接加5块砖变为888。。。
stk.pop();
}
else stk.push(h);
}
if(stk.size()<=1) printf("YES\n");
else printf("NO\n");
}
return 0;
}
D1. Great Vova Wall (Version 1)的更多相关文章
- Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ...
- CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)
http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...
- Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...
- Codeforces Round #527-D1. Great Vova Wall (Version 1)(思维+栈)
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)
http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...
- D2. Great Vova Wall (Version 2)
l链接 [https://codeforces.com/contest/1092/problem/D2] 题意 和D1一样只是不能竖直放了 分析 水平放的话,就只可能是相邻等时才可以,而且你会发现 只 ...
- Codeforces 1092 D2 Great Vova Wall (Version 2) (栈)
题意: 给一排砖,每列的高度$a_i$,问是否可以放1*2的砖,使得n列高度一样,砖只能横着放 思路: 每两个相邻的高度相同的砖可以变成大于等于它的高度的任意高度 所以像这样的 123321 是不满足 ...
- CF1092(div3):Great Vova Wall (栈)(还不错)
D1. Great Vova Wall (Version 1): 题意:给定长度为N的墙,以及每个位置的一些高度,现在让你用1*2的砖和2*1的砖去铺,问最后能否铺到高度一样. 思路:分析其奇偶性,在 ...
- Codeforces Global Round 7 D1. Prefix-Suffix Palindrome (Easy version)(字符串)
题意: 取一字符串不相交的前缀和后缀(可为空)构成最长回文串. 思路: 先从两边取对称的前后缀,之后再取余下字符串较长的回文前缀或后缀. #include <bits/stdc++.h> ...
随机推荐
- SQL Server DATA文件夹下audittrace20180124152845_52.trc类文件异常增多
同事告知某现场SQL Server2008R2数据库的DATA文件夹下audittrace开头的trc文件不断增多,占用较大空间,因此需要关停,尝试解决步骤如下: 1.查看是否有后台开启的trace ...
- 根据flickr id 下载图片
#coding=utf-8 import flickrapi import requests import os n=1 flickr=flickrapi.FlickrAPI('*********** ...
- SudokuGame 记软工第二次作业
整体概况 1.描述编写整体程序正确过程(含关键代码) 2.整体心路历程及新知分析 3.效能分析.构建之法及整体耗时时间表 4.一些心得体会 GitHub 链接如下: 1.[基础作业BIN文件(最新版) ...
- Go学习笔记08-包
Go学习笔记08-包 Go语言 封装 包 封装 CamelCase命名规则 首字母大写:public 首字母小写:private 包 一个目录即一个包 main包为可执行入口,只能有一个main包 为 ...
- 【English】20190306
Delivery team交付团队consumption消费[kənˈsʌmpʃən] The Consulting Delivery team is focused on delivering va ...
- WPFのDecorator 、Adorner和AdornerDecorator
Decorator 和 Adorner 它们都有“装饰品”的意思. Decorator类负责包装某个UI元素,以提供额外的行为.它有一个类型为UIElement的Child属性,其中含有待包装的内容. ...
- centos 7.2 64位安装redis
1.下载redis 可以在新建 /usr/local/redis 文件夹 $ wget http://download.redis.io/releases/redis-4.0.9.tar.gz $ ...
- UVA1153-Keep the Customer Satisfied(贪心)
Problem UVA1153-Keep the Customer Satisfied Accept: 222 Submit: 1706Time Limit: 3000 mSec Problem D ...
- 转://Oracle undo 自动调优
Oracle 10gr2的后续版本中添加了UNDO信息最短保留时间段自动调优的特性,不再仅仅依据参数UNDO_RETENTION的设定,其调优原则如下:1. 当UNDO TABLESPACE为 fix ...
- 【vue】vue +element 搭建项目,实现实时输入效果时停止输入后发送请求
1.实现的效果 输入关键字后,根据输入的关键字实时显示搜索的结果,按回车键时也进行搜索 2.原理: 通过时间戳+定时器+一个全局变量实现.代码量很少比较易懂. 用户输入时触发keyup事件,并调用事件 ...