Codeforces B. Coupons and Discounts
来源:互联网 发布:opta数据查询 编辑:程序博客网 时间:2024/05/22 04:49
题目:Coupons and Discounts
题意:买n天披萨,每天需买的披萨数已知,买披萨有俩种优惠:①连续俩天每天买一个(一共俩个)②一天买俩个,优惠可以无限次用。如果可以按优惠买完为YES,否则NO
思路:保证每天都是偶数即可满足(用②)!如果当天为奇数人,需要用①,所以当天人数减1,下一天人数减1,如果下一天人数为0,说明当天无法完成,即为NO,全部遍历完成后全部满足的话即为YES!
参考
代码:
#include <stdio.h>#include <stdlib.h>int a[200005];int main(){ int i,n; while(scanf("%d",&n)!=EOF) { int flag = 1; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i] & 1) { a[i]--; a[i+1]--; if(a[i+1] < 0 || i == n-1) {printf("NO\n");flag = 0;break;} } } if(flag) printf("YES\n"); } return 0;}
0 0
- Codeforces B. Coupons and Discounts
- 【codeforces 710 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
- B. Coupons and Discounts
- Codeforces Round #376 (Div. 2) B. Coupons and Discounts
- Codeforces Round #376 (Div. 2) B. Coupons and Discounts
- CodeForces 731B-Coupons and Discounts(贪心 模拟)
- CodeForces 731 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(贪心)
- 【贪心】Coupons and Discounts
- Coupons and Discounts(水题)
- 写在开始
- virtualbox安装centos6.5后获取不到ip
- php练习——用for循环打印半金字塔、金字塔、正方形、倒金字塔、菱形、空心图形等
- 如何用git将项目代码上传到github
- python多线程获取网络数据,与单线程进行比较
- Codeforces B. Coupons and Discounts
- SSL协议详解
- GITHUB自学系列之六「团队合作利器 BRANCH」
- 稀疏矩阵采用三元组存储,设计算法求两个矩阵的和。
- java Web工作原理
- ActiveMQ SSL应用之七 ActiveMQ管理控制台队列Send To功能的使用
- 浅析linux内核中的idr机制
- Java中成员变量和成员方法的使用
- iOS 语音搜索通讯录算法