1 条题解
-
0
C :
#include <stdio.h> int main() { int t; int ch[1000010]; scanf("%d", &t); for(int i = 0; i < t; i++) { scanf("%d", &ch[i]); } int Y25 = 0, Y50 = 0; for(int i = 0; i < t; i++ ) { if(ch[i] == 25) { Y25++; } else if(ch[i] == 50) { if(Y25 > 0) { Y25--; Y50++; } else { printf("NO"); return 0; } } else { if(Y50 > 0 && Y25 > 0) { Y50--; Y25--; } else if(Y25 >= 3) { Y25 -= 3; } else { printf("NO"); return 0; } } } if(Y25 >= 0 && Y50 >= 0) { printf("YES"); } else { printf("NO"); } return 0; }C++ :
#include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10; typedef pair<int,int> PII; typedef priority_queue<int , vector<int>, greater<int>> minqueue; //从小到大 queue typedef priority_queue<int, vector<int>, less<int>> maxqueue; //从大到小 queue int gcd(int a, int b){ //最大公因数 return b ? gcd(b, a % b) : a; } int lcm(int a, int b){ //最小公倍数 return a * b / __gcd(a, b); } int qmi(int base, int power, int p) //快速幂求余 { int result = 1; while (power > 0) { if (power & 1) result = result * base % p; base = base * base % p ; power >>= 1; } return result % p; } int a[N],x25=0,x50=0; void solve() { int n; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++){ if(a[i]==25) x25++; else if(a[i]==50){ x25--; x50++; } else{ if(x25>0&&x50>0){ x25--; x50--; } else x25-=3; } if(x25<0||x50<0){ cout<<"NO"<<'\n'; return; } } cout<<"YES"<<'\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; t=1; //cin>>t; while(t--) { solve(); } return 0; }
- 1
信息
- ID
- 717
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 9
- 标签
- 提交数
- 19
- 已通过
- 3
- 上传者