Codeforces 731B Coupons and Discounts(贪心)

题目链接 Coupons and Discounts

逐步贪心即可。

若当前位为奇数则当前位的下一位减一,否则不动。

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 #define rep(i,a,b)              for(int i(a); i <= (b); ++i)
 6 
 7 int a[200010];
 8 int n;
 9 
10 int main(){
11 
12 
13     memset(a, 0, sizeof a);
14     scanf("%d", &n);
15     rep(i, 1, n) scanf("%d", a + i);
16     bool flag = true;
17     rep(i, 1, n + 1){
18         if (a[i] < 0){
19             flag = false;
20             break;
21         }
22 
23         if (i == n + 1) break;
24         if (a[i] & 1){
25             --a[i + 1];
26         }
27     }
28 
29     puts(flag ? "YES" : "NO");
30     return 0;
31 
32 }
原文地址:https://www.cnblogs.com/cxhscst2/p/6441462.html