A - Subtle Substring Subtraction
/* * __----~~~~~~~~~~~------___ * . . ~~//====...... __--~ ~~ * -. \_|// |||\\ ~~~~~~::::... /~ * ___-==_ _-~o~ \/ ||| \\ _/~~- * __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ * _-~~ .=~ | \\-_ '-~7 /- / || \ / * .~ .~ | \\ -_ / /- / || \ / * / ____ / | \\ ~-_/ /|- _/ .|| \ / * |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ * ' ~-| /| |-~\~~ __--~~ * |-~~-_/ | | ~\_ _-~ /\ * / \ \__ \/~ \__ * _--~ _/ | .-~~____--~-/ ~~==. * ((->/~ '.|||' -_| ~~-/ , . _|| * -_ ~\ ~~---l__i__i__i--~~_/ * _-~-__ ~) \--______________--~~ * //.-~~~-~_--~- |-------~~~~~~~~ * //.-~~~--\ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 神兽保佑 永无BUG */ #include<bits/stdc++.h> #define int long long using namespace std; void solve() { string s; cin>>s; int len=s.size(); int suma=0,sumb=0; for(int i=0;i<s.size();i++) suma+=(s[i]-'a'+1); if(s.size()%2==0) return cout<<"Alice "<<suma<<endl,void(); sumb=min(s[len-1]-'a'+1,s[0]-'a'+1); // cout<<suma<<' '<<sumb<<endl; suma-=sumb; if(sumb>suma) return cout<<"Bob "<<sumb-suma<<endl,void(); else return cout<<"Alice "<<suma-sumb<<endl,void(); } signed main() { int t; cin>>t; while(t--) solve(); return 0; }
B - A Perfectly Balanced String?
#include<bits/stdc++.h> using namespace std; const int N=2e5+10; void solve() { string s; cin>>s; bool f1=false,f2=false; int len=s.size(),num=0; map<char,int>mp; for(int i=0;i<len;i++){ if(s[i]!=s[0]) f1=true; if(mp[s[i]]==0) num++; mp[s[i]]++; if(mp[s[i]]>=2) f2=true; } if(!f1||!f2) return cout<<"Yes"<<endl,void(); mp.clear(); for(int i=num;i<len;i++) if(s[i]!=s[i-num]) return cout<<"No"<<endl,void(); cout<<"Yes"<<endl; } int main() { int t; cin>>t; while(t--){ solve(); } } //第二种: #include<bits/stdc++.h> using namespace std; const int N=2e5+10; string s; int n,m; bool check(char x,char y) { int cur=0; for(auto c:s){ if(c==x) cur--,cur=(cur<0)?0:cur; if(c==y) cur++; if(cur>1) return false; } return true; } void solve() { cin>>s; map<char,int>mp; for(auto c:s) mp[c]++; for(char i='a';i<='z';i++){ if(!mp[i]) continue; for(char j='a';j<='z';j++){ if(!mp[j]||i==j) continue; if(!check(i,j)) return cout<<"No"<<endl,void(); } } cout<<"Yes"<<endl; } int main() { int t;cin>>t;while(t--) solve(); }
#include<bits/stdc++.h> #define int long long using namespace std; const int N=5e4+10,mod=1e9+7; bool vis[N]; int dp[N]; bool check(int x) { string s=to_string(x); for(int i=0,j=s.size()-1;i<j;i++,j--) if(s[i]!=s[j]) return false; return true; } void solve() { int n; cin>>n; cout<<dp[n]<<endl; } signed main() { for(int i=1;i<=50000;i++) if(check(i)) vis[i]=true; vector<int>w; w.push_back(-1); for(int i=1;i<=50000;i++) if(vis[i]) w.push_back(i); dp[0]=1; for(int i=1;i<=w.size()-1;i++) for(int j=w[i];j<=50000;j++) dp[j]=(dp[j-w[i]]+dp[j])%mod; int t; cin>>t; while(t--) solve(); return 0; }
标签:__,785,return,int,Codeforces,--,solve,Div,-_ From: https://www.cnblogs.com/o-Sakurajimamai-o/p/17844241.html