Codeforces Round #552 (Div. 3)

A

# include <bits/stdc++.h>
using namespace std;

typedef long long LL;
int main()
{
	LL x[5];
	LL a,b,c;
	
	scanf("%lld %lld %lld %lld",&x[0],&x[1],&x[2],&x[3]);
	
	
	sort(x,x+4);
	
	a=x[3]-x[0];
	b=x[3]-x[1];
	c=x[3]-x[2];
	
	printf("%lld %lld %lld",a,b,c);
	
	return 0;
 } 

B

# include <bits/stdc++.h>
using namespace std;

const int INF=1e9;
int a[110];
int f[110];
int g[110];
int main()
{
	int n;
	int sum=0;
	
	scanf("%d",&n);	
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(f[a[i]]==0){
			f[a[i]]=1;
			sum++;
		}
	}
	
	if(sum>3){
		printf("-1");
		return 0;
	}else{
		int b=0;
		for(int i=0;i<110;i++){
			if(f[i]){
				g[b++]=i;
			}
		}
		if(b==3){
			for(int i=0;i<(b-1);i++){
				g[i]=g[i+1]-g[i];
			}
	//		for(int i=0;i<(b-1);i++){
	//			cout<<g[i]<<endl;
	//		}
			//cout<<b<<endl;
			for(int i=0;i<(b-2);i++){
				if(g[i]!=g[i+1]){
					printf("-1");
					return 0;
				}
			}
			printf("%d",g[0]);
		}else if(b==2){
			int c=g[1]-g[0];
			if(c%2==1){
				printf("%d",c);
			}else{
				printf("%d",c/2);
			}
		}else if(b==1){
			printf("0");
		}else{
			printf("-1");
		}
	}
	
	
	return 0;
}

C

# include <bits/stdc++.h>
using namespace std;

typedef long long LL;
int main()
{
	LL a,b,c;
	LL ans=0;
	LL d[20]={0,1,2,3,1,3,2,1,1,2,3,1,3,2,1};
	
	scanf("%lld %lld %lld",&a,&b,&c);
	
	while(a>=3&&b>=2&&c>=2){
		a-=3;
		b-=2;
		c-=2;
		ans+=7; 
	}
	if(!a&&!b&&!c){
		printf("%lld",ans);
		return 0;
	}
	LL maxx=0;
	for(int i=1;i<=7;i++){
		LL a1=a,b1=b,c1=c;
		LL l=i;
		LL res=0;
		while(l<=14){
			if(d[l]==1){
				if(a1>0){
					a1--;
					res++;
				}else{
					break;
				}
			}
			else if(d[l]==2){
				if(b1>0){
					b1--;
					res++;
				}else{
					break;
				}
			}
			else if(d[l]==3){
				if(c1>0){
					c1--;
					res++;
				}else{
					break;
				}
			}
			l++;
		}
		//cout<<maxx<<endl;
		maxx=max(maxx,res);
	}
	//cout<<maxx<<" "<<ans<<endl;
	printf("%lld",maxx+ans);
	return 0;
}

D

# include <bits/stdc++.h>
using namespace std;
//题目意思就是说,机器人正在从x=0走到x=n
//s[i]=1 说明当前段暴露在阳光下,s[i]=0 说明当前段没有在阳光下
//机器人有两种  电池 容量b   蓄电池 容量a   
//两种只要使用都会-1  但是在阳光下是用电池,蓄电池会+1 

int main()
{
	int n,b,a;
	int t,i;
	
	scanf("%d %d %d",&n,&b,&a);
	int c=a;
	for(i=1;i<=n;i++){
		scanf("%d",&t);
		if(t==0||a>=c||b<=0){
			if(a>0){
				a--;
			}else if(b>0){
				b--;
			}else{
				i--;
				break; 
			}
		}else{
			b--;
			a++;
		}
	} 
	
	printf("%d",min(i,n));
	//min(i,n) 就不用判断是否是最后加过头了 
	return 0;
}

E

# include <bits/stdc++.h>
using namespace std;

typedef long long LL;
LL a[200010];
LL f[200010];
int main()
{
	LL n,k,nn;
	
	scanf("%lld %lld",&n,&k);
	nn=n;
	
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	
	LL c=1;
	while(nn>0){
		//cout<<nn<<endl;
		LL maxx=0;
		LL d=0;
		LL ff=1;
		if(c%2==1) ff=1;
		else ff=2;
		c++;
		for(int i=0;i<n;i++){
			if(a[i]>maxx&&f[i]==0){
				maxx=a[i];
				d=i;
			}
		}
		a[d]=0;
		f[d]=ff;
		nn--;
		LL len=0;
		for(int j=(d+1);j<n;j++){
			if(len==k) break;
			if(a[j]!=0){
				a[j]=0;
				f[j]=ff;
				nn--;
				len++;
			}
		}
		len=0;
		for(int j=(d-1);j>=0;j--){
			if(len==k) break;
			if(a[j]!=0){
				a[j]=0;
				f[j]=ff;
				nn--;
				len++;
			}
		}
	}
	
	for(int i=0;i<n;i++){
		printf("%lld ",f[i]);
	}
	return 0;
}

posted @ 2022-02-27 00:08  fengzlj  阅读(27)  评论(0)    收藏  举报