A title
Water problem, but I do in trouble, because I do not know the internal string can also sort, learned a trick
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; const int N=1e5+10; const int inf=0x3f3f3f3f; int a[27],b[27]; int main(){ int t; cin>>t; while(t--){ string p; string s; cin>>p>>s; int i; int l1=s.size(); int l2=p.size(); int flag=0; if(l1<l2){ cout<<"NO"<<endl; continue; } for(i=0;i<l1-l2+1;i++){ memset(a,0,sizeof a); memset(b,0,sizeof b); flag=0; string tmp=s.substr(i,l2); int j; for(j=0;j<p.size();j++){ int sign=p[j]-'a'; a[sign]++; } for(j=0;j<tmp.size();j++){ int sign=tmp[j]-'a'; b[sign]++;} for(j=0;j<26;j++){ if(a[j]!=b[j]){ flag=1; break; }} if(flag==0){ cout<<"YES"<<endl; break; } } if(flag==1) cout<<"NO"<<endl; }}
B title
math problem
Of course, is to calculate the difference, we naturally want to have a small increase approaching that big, so we take the prefix and requirements
We can know, and know the difference between prefixes and parity on the same line
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; const int N=1e5+10; const int inf=0x3f3f3f3f; int main(){ int t; cin>>t; while(t--){ int s[N]={0}; int a,b; cin>>a>>b; if(a>b) swap(a,b); int sum=b-a; int i; for(i=1;i<N;i++){ s[i]=s[i-1]+i; } if(sum==0) cout<<0<<endl; else{ for(i=1;i<N;i++){ if(s[i]-sum>=0&&(s[i]-sum)%2==0){ cout<<i<<endl; break; } } } } }
C title
This problem as long as the strike prefixes and suffixes opposite to each other in a number of cases to a minimum
To this question must be converted to 2-1, such as two types of contributions to the job equal
tip: use map
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<map> using namespace std; const int N=2e5+10; const int inf=0x3f3f3f3f; int main(){ int t; cin>>t; while(t--){ int s[N]={0}; map<int,int> pos; int i; int n; cin>>n; pos[0]=0; for(i=1;i<=2*n;i++){ int a; cin>>a; if(a==2) a=-1; s[i]=s[i-1]+a; if(i<=n) pos[s[i]]=i; } int res=2*n; for(i=n;i<=2*n;i++){ auto it=pos.find(s[i]-s[2*n]); if(it!=pos.end()) res=min(res,i-it->second); } cout<<res<<endl; } }