J - Straight Master Gym - 101775J 差分
题意:纸牌顺子:连续的3张或连续的4张或连续的5张为顺子。手中的牌共有n个数字,每个数字是a[i]个,能不能把手中所有的牌都是属于顺子。
- 1 ≤ T ≤ 100.
- 1 ≤ N ≤ 2 × 105.
- 0 ≤ ai ≤ 109.
- .
#include <bits/stdc++.h> #define rep(i, a, b) for(int i = a; i <= b; i++) #define ll long long using namespace std; const int maxn = 1e6; const ll INF = 0x3f3f3f3f3f3f3f; ll a[maxn], b[maxn]; int main(){ ios::sync_with_stdio(false); int t, k = 0; cin >> t; while(t--){ int n; cin >> n; rep(i, 1, n){ cin >> a[i]; b[i] = a[i] - a[i-1]; } b[n+1] = -a[n]; int tot = 0; rep(i, 1, n+1){ if(b[i] >= 0) tot += b[i]; else {tot = 1; break;} int pos = i+3; if(pos > n+1) break; if(b[pos] < 0) tot += b[pos], b[pos] = 0; if(tot < 0) break; } printf("Case #%d: ", ++k); if(tot) printf("No\n"); else printf("Yes\n"); } return 0; }