CodeForces 731 B.Coupons and Discounts(水~)
来源:互联网 发布:专业知乎 编辑:程序博客网 时间:2024/05/28 14:56
Description
n天,第i天需要ai个披萨,有两种买法,第一种是一次买俩,第二种是连续两天一天买一个总共两个,当天买的披萨必须当天吃,买多了就浪费了,问是否会浪费
Input
第一行一整数n表示天数,之后n个整数a[i]表示每天所需的披萨数量(1<=n<=2e5,0<=a[i]<=1e4)
Output
如果存在不浪费的方案则输出YES,否则输出NO
Sample Input
4
1 2 1 2
Sample Output
YES
Solution
前i-1天都解决了的情况下,如果a[i]为奇且a[i+1]为0,那么就一定会浪费,输出NO,否则a[i+1]–,最后判断a[n]为奇为偶,为奇则输出NO,为偶则输出YES
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 222222int n,a[maxn];int main(){ while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) scanf("%d",&a[i]); int gg=0; for(int i=1;i<n;i++) if(a[i]&1) { if(!a[i+1]) { gg=1; break; } else a[i+1]--; } if(a[n]&1)gg=1; printf("%s\n",gg?"NO":"YES"); } return 0;}
0 0
- CodeForces 731 B.Coupons and Discounts(水~)
- 【50.49%】【codeforces 731B】Coupons and Discounts
- Codeforces 731 B. Coupons and Discounts【贪心】
- CodeForces 731B Coupons and Discounts
- CodeForces 731B 之 Coupons and Discounts
- Codeforces 731 B. Coupons and Discounts
- codeforces 731B Coupons and Discounts
- CodeForces 731B-Coupons and Discounts(贪心 模拟)
- Codeforces B. Coupons and Discounts
- 【codeforces 710 B Coupons and Discounts】
- B. Coupons and Discounts
- Codeforce 731B. Coupons and Discounts
- 【Codeforces Round #376 (Div. 2)】 Codeforces 731B Coupons and Discounts
- Codeforces Round #376 (Div. 2) B. Coupons and Discounts
- Codeforces Round #376 (Div. 2) B. Coupons and Discounts
- Codeforces Round #376 (Div. 2) B. Coupons and Discounts(贪心)
- Coupons and Discounts(水题)
- Coupons and Discounts(细节题)
- Java使用JDBC连接MySQL数据库
- 如何在Eclipse中Debug调试Java jdk源代码
- 内核栈溢出保护
- Python爬虫入门 (一)
- what is *.php.inc, and why using it?
- CodeForces 731 B.Coupons and Discounts(水~)
- String.format的不为人知的用法
- tensorflow学习存在的问题
- C# 进制转换(二进制、十六进制、十进制互转)
- 用户运营的最大误区:你以为你以为的就是用户以为的?
- mapperLocations与MapperScannerConfigurer
- grunt-ts编译成es5报错
- [java]使用httpclient4.5.3设置fiddler代理方法
- cksum与md5sum实现文件校验