ABC294(A-F)

AtCoder Beginner Contest 294
Contest Duration: 2023-03-19(Sun) 20:00 - 21:40 (local time) (100 minutes)

A Filter

ABC294(A-F)_第1张图片
按顺序输出偶数

	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

ABC294(A-F)_第2张图片
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

ABC294(A-F)_第3张图片
归并排序,按序输出每个元素在新数组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

ABC294(A-F)_第4张图片
ABC294(A-F)_第5张图片
题意需要理解一下,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

ABC294(A-F)_第6张图片
ABC294(A-F)_第7张图片
ABC294(A-F)_第8张图片
数组给出方式是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;

F - Sugar Water 2

ABC294(A-F)_第9张图片
ABC294(A-F)_第10张图片
ABC294(A-F)_第11张图片
ABC294(A-F)_第12张图片
来自SoyTony

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";

你可能感兴趣的:(acm,算法,c++)