ABC294(A-E)
AtCoder Beginner Contest 294
Contest Duration: 2023-03-19(Sun) 20:00 - 21:40 (local time) (100 minutes)
A Filter
按顺序输出偶数
int n;cin>>n;
int a[n];fer(i,0,n)cin>>a[i];
fer(i,0,n){
if(!(a[i]&1))cout<<a[i]<<" ";
}
B ASCII Art
0输出"." 其他按序输出26个字母
int h,w;cin>>h>>w;
int a[h][w];
fer(i,0,h){
fer(j,0,w)cin>>a[i][j];
}
fer(i,0,h){
fer(j,0,w){
if(!a[i][j])cout<<".";
else cout<<(char)(a[i][j]-1+'A');
}
cout<<endl;
}
C Merge Sequences
归并排序,按序输出每个元素在新数组C里的位置,双指针
int n,m;cin>>n>>m;
fer(i,0,n)cin>>a[i];
fer(j,0,m)cin>>b[j];
int i=0,j=0,k=0;
while(i<n&&j<m){
if(a[i]<b[j]){
resa[i]=k++;i++;
}else{
resb[j]=k++;j++;
}
}
while(i<n){
resa[i]=k++;i++;
}
while(j<m){
resb[j]=k++;j++;
}
fer(i,0,n)cout<<resa[i]+1<<" ";
cout<<endl;
fer(i,0,m)cout<<resb[i]+1<<" ";
D Bank
题意需要理解一下,1:叫号,2:客户前往柜台,3:再叫 过号的人
叫号从小到大,前往柜台无限制
集合本身按序储存,用集合就可以
int n,q;cin>>n>>q;
int k=1;
set<int> s;
while(q--){
int op;cin>>op;
if(op==1){
s.insert(k++);
}else if(op==2){
int x;cin>>x;
s.erase(x);
}else{
set<int>:: iterator it=s.begin();
cout<<*it<<endl;
}
}
E 2xN Grid
数组给出方式是l个数字v,求上下相同的格子组数
L是1e12,故不能遍历,而且只求格子组数,不需要输出格子编号
双指针
用数组存也可以
#define pb push_back
int l,n1,n2;cin>>l>>n1>>n2;
vector<int> a,al,b,bl;
fer(i,0,n1){
int v,len;cin>>v>>len;
a.pb(v);al.pb(len);
}
fer(i,0,n2){
int v,len;cin>>v>>len;
b.pb(v);bl.pb(len);
}
int i=0,j=0,cnt=0;
int starta=0,enda=al[0],startb=0,endb=bl[0];
while(i<n1&&j<n2){
if(a[i]==b[j])cnt+=min(enda,endb)-max(starta,startb);
if(enda<endb){
i++;starta=enda;enda=starta+al[i];
}else {
j++;startb=endb;endb=startb+bl[j];
}
}
cout<<cnt<<endl;