Codeforces Round #715 (Div. 2)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #715 (Div. 2)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Codeforces Round #715 (Div. 2)
| A | Average Height | |
| B | TMT Document | |
| C | The Sports Festival | 區間dp |
| D | Binary Literature | 構造題 |
| E | Almost Sorted | |
| F | Complete the MST |
A
題意:
如果兩個相鄰的數的和是偶數,則貢獻為1
如何排序使得貢獻值最大
題解:
奇+奇=偶
偶+偶=偶
把奇數放一起,把偶數放一起,然后輸出
代碼:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string> #include<queue> #include<stack> #define debug(x) printf("x = %d\n",x); typedef long long ll; using namespace std; inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);return s*w; } const int maxn=2e4+9; int a[maxn]; int b[maxn]; int main() {int t ;cin>>t;while(t--){int tota=0;int totb=0;int n;cin>>n;for(int i=1;i<=n;i++){int x;cin>>x;if(x%2==0)a[++tota]=x;else b[++totb]=x;}for(int i=1;i<=tota;i++){printf("%d ",a[i]);}for(int i=1;i<=totb;i++){printf("%d ",b[i]);}cout<<endl;} }B
題意:
給你一個T和M組成的字符串,問這個字符串能否拆分成數個子序列TMT
題解:
先看T的數量是否為M的兩倍,然后從左往右,依次讀,遇到T,ans++,遇到M,ans–,如果ans中途為負,或者讀完字符串ans不為9,則答案為NO
然后倒著也來一遍
代碼:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string> #include<queue> #include<stack> #define debug(x) printf("x = %d\n",x); typedef long long ll; using namespace std; inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);return s*w; } int main() {int t;cin>>t;while(t--){int n;cin>>n;string s;cin>>s;int ans1=0,ans2=0;bool f=0;for(int i=0;i<n;i++){if(s[i]=='T')ans1++;else ans2++;}if(ans1!=(ans2*2)){cout<<"NO"<<endl;continue;}ans1=0,ans2=0;for(int i=0;i<n;i++){if(s[i]=='T')ans1++;else {if(ans1==0){cout<<"NO"<<endl;f=1;break;}else {ans1--;}}}if(f==1){continue;}ans1=0,ans2=0;for(int i=n-1;i>=0;i--){if(s[i]=='T')ans1++;else {if(ans1==0){cout<<"NO"<<endl;f=1;break;}else {ans1--;}}}if(f==0)cout<<"YES"<<endl;}return 0; }總結
以上是生活随笔為你收集整理的Codeforces Round #715 (Div. 2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 青麻的功效与作用是什么
- 下一篇: cf1511B. GCD Length