A.题目链接:http://codeforces.com/contest/828/problem/A
解题思路:
直接暴力模拟
#include<bits/stdc++.h> using namespace std; int main() { int m,d,s,i,num=0,ans=0,a[200009]; cin>>m>>d>>s; for(i=0;i<m;i++){ cin>>a[i]; if(a[i]==1&&d) d--; else if(a[i]==1&&d==0&&s){ s--;num++; } else if(a[i]==2&&s){ s--; } else if(a[i]==2&&s==0) ans+=2; else if(a[i]==1&&s==0&&d==0&&num) num--; else if(a[i]==1&&s==0&&d==0&&num==0) ans++; } cout<<ans<<endl; }
B.题目链接:http://codeforces.com/contest/828/problem/B
思路:
暴力
#include<bits/stdc++.h> using namespace std; #define inf 2e9 int main() { char mp[110][110]; int m,n,i,j,num=0,ans=0; cin>>m>>n; for(i=1;i<=m;i++){ for(j=1;j<=n;j++){ cin>>mp[i][j]; } } int maxi = -inf,maxj = -inf; int mini = inf,minj=inf; for(i=1;i<=m;i++){ for(j=1;j<=n;j++){ if(mp[i][j]=='B'){ if(i>maxi) maxi = i; if(i<mini) mini = i; if(j>maxj) maxj = j; if(j<minj) minj = j; num+=1; } } } if(num==0){ cout<<"1"<<endl; return 0;} //cout<<num<<endl; ans = max((maxi-mini+1),(maxj - minj+1)); //cout<<ans<<endl; if(ans>m||ans>n) cout<<"-1"<<endl; else{ cout<<ans*ans-num<<endl; } return 0; }
C.题目链接:http://codeforces.com/contest/828/problem/C
解题思路:
暴力会超时,he前一区域比较,如果没有重合的进行替换操作,重合跳过;
#include<bits/stdc++.h> using namespace std; char s[3000009]; int main() { int m,n,i,j,k,pre,x,maxx = -9999999; string s1; ios::sync_with_stdio(false); cin.tie(0); cin>>m; memset(s,'a',sizeof(s)); while(m--){ cin>>s1>>n; int len = s1.size(); pre = -len; for(i=0;i<n;i++){ cin>>x; for(k=max(0,len-(x-pre));k<len;++k){ s[x+k-1] = s1[k]; pre = x; } maxx = max(maxx,x+len-1); } } for(i=0;i<maxx;i++) cout<<s[i]; cout<<endl; return 0; }