Educational Codeforces Round 43 (Rated for Div. 2) A B C

时间:2022-09-12 11:30:07

A.

#include<iostream>
#include<cstring>
using namespace std;

int main(){
	int i,n,j;
	j=0;
	string s;
	cin>>n;
	cin>>s;
	for(i=0;i<n;i++){
		if(s[i]=='0') j++;
	}
	if(n==1&&j==1) cout<<"0"<<endl;
	else{
		cout<<"1";
		for(i=1;i<=j;i++){
			cout<<"0";
		}
		cout<<endl;
	}
	return 0;
} 

B.
直接模拟明显炸,所以....找规律了(注意n*m是爆int的卡了好久。。。。还是太菜了)

#include<iostream>

using namespace std;

int main(){
	long long i,j,n,m,k,t;
	cin>>n>>m>>k;
	if(k<=n-1){
		cout<<k+1<<" "<<1<<endl;
	}
	if(k>n-1&&k<=n+m-2) cout<<n<<" "<<k-n+2<<endl;
	if(k<m*n-1&&k>m+n-2){
		t=(k-m-n+2)/(m-1);
		if(t<(k-m-n+2)*1.0/(m-1)) t++;
		j=(k-m-n+2)%(m-1);
		if(j==0) j=m-1;
		if(t%2){
			cout<<n-t<<" "<<m-j+1<<endl;
		}
		else {
			cout<<n-t<<" "<<j+1<<endl;
		}
	}
	if(k>=m*n-1) cout<<1<<" "<<2<<endl;
	return 0;
}

C.预先按首尾sort一下然后从头和尾扫两次就可以了,因为只从头扫会漏掉一种情况,因为题目只要输出一个存在就可以了所以On就能过。

#include<iostream>
#include<algorithm>

using namespace std;
struct su{
	int n,m,b;
}a[300005];

int cmp(su a,su b){
	if(a.m==b.m) return a.n<b.n;
	return a.m<b.m;
}//sort的关键。

int main(){
	int t,i,j,flag=0;
	cin>>t;
	for(i=1;i<=t;i++)
	{
	cin>>a[i].m>>a[i].n;
	a[i].b=i;
    }
	sort(a+1,a+1+t,cmp);
	for(i=1;i<t;i++){
		if(a[i].m<=a[i+1].m&&a[i].n>=a[i+1].n){
			cout<<a[i+1].b<<" "<<a[i].b<<endl;
			flag=1;
			break;
		}
	}
	if(flag) return 0;
	for(i=t;i>1;i--){
		if(a[i].m==a[i-1].m&&a[i].n>=a[i-1].n){
			cout<<a[i-1].b<<" "<<a[i].b<<endl;
			flag=1;
			break;
		}
	}//两次扫描
	if(flag==0) cout<<-1<<" "<<-1<<endl;

	return 0;
}