AtCoder Beginner Contest 294
Contest Duration: 2023-03-19(Sun) 20:00 - 21:40 (local time) (100 minutes)
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]<<" ";
}
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;
}
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<<" ";
题意需要理解一下,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;
}
}
数组给出方式是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;
long long N, M, K;
cin >> N >> M >> K;
vector<long long> A(N), B(N), C(M), D(M);
for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
for (int i = 0; i < M; i++) cin >> C[i] >> D[i];
double ng = 0, ok = 1;
for (int iter = 0; iter < 100; iter++) {
double x = (ng + ok) / 2;//浓度
double z = x / (1 - x);//每克混合物含糖量
vector<double> v(M);
for (int i = 0; i < M; i++) v[i] = C[i] - D[i] * z;
sort(begin(v), end(v));
long long num = 0;
for (int i = 0; i < N; i++) {
double w = A[i] - B[i] * z;
num += M - (lower_bound(begin(v), end(v), -w) - begin(v));
}
(num < K ? ok : ng) = x;
}
cout << fixed << setprecision(16) << ok * 100 << "\n";