日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #715 (Div. 2)

發布時間:2023/12/3 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #715 (Div. 2) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Codeforces Round #715 (Div. 2)

題號題目知識點
AAverage Height
BTMT Document
CThe Sports Festival區間dp
DBinary Literature構造題
EAlmost Sorted
FComplete 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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。