Codeforces Beta Round #54 (Div. 2)
Codeforces Beta Round #54 (Div. 2)
http://codeforces.com/contest/58
A
找子序列
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1000005 9 #define rep(k,i,j) for(int k=i;k<j;k++) 10 typedef long long ll; 11 typedef unsigned long long ull; 12 13 14 int main(){ 15 #ifndef ONLINE_JUDGE 16 // freopen("input.txt","r",stdin); 17 #endif 18 std::ios::sync_with_stdio(false); 19 string str; 20 string s="hello"; 21 cin>>str; 22 int i=0,j=0; 23 while(i<s.length()&&j<str.length()){ 24 if(s[i]==str[j]){ 25 i++,j++; 26 } 27 else{ 28 j++; 29 } 30 } 31 if(i==s.length()){ 32 cout<<"YES"<<endl; 33 } 34 else cout<<"NO"<<endl; 35 }
B
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1000005 9 #define rep(k,i,j) for(int k=i;k<j;k++) 10 typedef long long ll; 11 typedef unsigned long long ull; 12 13 14 int main(){ 15 #ifndef ONLINE_JUDGE 16 // freopen("input.txt","r",stdin); 17 #endif 18 std::ios::sync_with_stdio(false); 19 int n; 20 cin>>n; 21 for(int i=n;i>=1;i--){ 22 if(n%i==0){ 23 cout<<i<<" "; 24 n=i; 25 } 26 } 27 }
C
逆向思维,求出最多不需要修改的数量,然后减去它即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1000005 9 #define rep(k,i,j) for(int k=i;k<j;k++) 10 typedef long long ll; 11 typedef unsigned long long ull; 12 13 int n; 14 int a[100005]; 15 16 int main(){ 17 #ifndef ONLINE_JUDGE 18 // freopen("input.txt","r",stdin); 19 #endif 20 std::ios::sync_with_stdio(false); 21 cin>>n; 22 int m; 23 int ans=0; 24 for(int i=1;i<=n;i++){ 25 cin>>m; 26 int num=min(i,n-i+1); 27 m-=num; 28 if(m>=0){ 29 a[m]++; 30 ans=max(ans,a[m]); 31 } 32 } 33 cout<<n-ans<<endl; 34 35 }
D
在每个字符串后面加上字符d,然后sort+贪心即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1000005 9 #define rep(k,i,j) for(int k=i;k<j;k++) 10 typedef long long ll; 11 typedef unsigned long long ull; 12 13 int n; 14 string str[20004]; 15 int book[20004]; 16 string ans[20004]; 17 string d; 18 19 int main(){ 20 #ifndef ONLINE_JUDGE 21 // freopen("input.txt","r",stdin); 22 #endif 23 std::ios::sync_with_stdio(false); 24 cin>>n; 25 int sum=0; 26 for(int i=1;i<=n;i++){ 27 cin>>str[i]; 28 sum+=str[i].length(); 29 } 30 cin>>d; 31 for(int i=1;i<=n;i++){ 32 str[i]+=d; 33 } 34 sum+=n/2; 35 int len=sum/(n/2); 36 int co=1; 37 sort(str+1,str+n+1); 38 for(int i=1;i<=n;i++){ 39 if(!book[i]){ 40 ans[co]=str[i]; 41 book[i]=1; 42 for(int j=1;j<=n;j++){ 43 if(!book[j]&&str[i].length()-1+str[j].length()==len){ 44 ans[co]+=str[j].substr(0,str[j].length()-1); 45 book[j]=1; 46 co++; 47 break; 48 } 49 } 50 } 51 } 52 for(int i=1;i<co;i++){ 53 cout<<ans[i]<<endl; 54 } 55 }
E
搜索
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1000005 9 #define rep(k,i,j) for(int k=i;k<j;k++) 10 typedef long long ll; 11 typedef unsigned long long ull; 12 13 ll ans1,ans2; 14 ll p[15]; 15 ll ans=13; 16 void dfs(ll a,ll b,ll c,ll ra,ll rb, ll jw, ll inc,ll d){ 17 if(inc>=ans) return; 18 if(!a&&!b&&!c&&!jw){ 19 ans=inc;ans1=ra;ans2=rb;return; 20 } 21 if(!c){ 22 ll s=a+b+jw; 23 int k=0; 24 while(s){ 25 s/=10; 26 k++; 27 } 28 dfs(0,0,0,a*p[d]+ra,b*p[d]+rb,0,inc+k,d); 29 return; 30 } 31 if((a+b+jw)%10==c%10){ 32 dfs(a/10,b/10,c/10,a%10*p[d]+ra,b%10*p[d]+rb,(a%10+b%10+jw)/10,inc,d+1); 33 } 34 else{ 35 dfs(a*10+(c+10-b%10-jw)%10,b,c,ra,rb,jw,inc+1,d); 36 dfs(a,b*10+(c+10-a%10-jw)%10,c,ra,rb,jw,inc+1,d); 37 dfs(a,b,c*10+(a+b+jw)%10,ra,rb,jw,inc+1,d); 38 } 39 } 40 41 42 int main(){ 43 #ifndef ONLINE_JUDGE 44 // freopen("input.txt","r",stdin); 45 #endif 46 std::ios::sync_with_stdio(false); 47 ll a,b,c; 48 char ch; 49 cin>>a>>ch>>b>>ch>>c; 50 p[0]=1; 51 for(int i=1;i<=13;i++) p[i]=p[i-1]*10; 52 dfs(a,b,c,0,0,0,0,0); 53 cout<<ans1<<"+"<<ans2<<"="<<ans1+ans2<<endl; 54 }
posted on 2019-02-25 11:22 Fighting_sh 阅读(163) 评论(0) 编辑 收藏 举报