当前位置:   article > 正文

2023年蓝桥杯C++C组—三国游戏_蓝桥杯c组集训

蓝桥杯c组集训

题目描述

在这里插入图片描述

解题代码

#include<bits/stdc++.h> 
using namespace std;
#define ll long long int 
int main(){
	vector<int>x1,x2,y1,y2,z1,z2;
	int n,x0=0,y0=0,z0=0;
	cin>>n;
	int q[n],w[n],e[n];
	for(int i=0;i<n;i++){
		cin>>q[i];
	}
	for(int i=0;i<n;i++){
		cin>>w[i];
	}
	for(int i=0;i<n;i++){
		cin>>e[i];
	}
	for(int i=0;i<n;i++){
		int a=q[i]-w[i]-e[i];
		int b=w[i]-q[i]-e[i];
		int c=e[i]-q[i]-w[i];
		if(a<0) x1.push_back(a);else if(a==0) x0++;else if(a>0) x2.push_back(a);
		if(b<0) y1.push_back(b);else if(b==0) y0++;else if(b>0) y2.push_back(b);
		if(c<0) z1.push_back(c);else if(c==0) z0++;else if(c>0) z2.push_back(c);  
	}
	//x0为等于0的方案,x1为小于0的,x2为大于0的 
	sort(x1.begin(),x1.end(),greater<int>());
	sort(y1.begin(),y1.end(),greater<int>());
	sort(z1.begin(),z1.end(),greater<int>());
	int ans1=0,ans2=0,ans3=0;
	
	if(!x2.empty()){
		ans1+=x0;
		ll sum=0;
		for(auto it=x2.begin();it!=x2.end();it++){
			sum+=*it;
			ans1++;
		}
		for(auto it=x1.begin();it!=x1.end();it++){
			sum+=*it;
			if(sum>0){
				ans1++;
			}else{
				break;
			}
		}
	}
	
	if(!y2.empty()){
		ans2+=z0;
		int sum=0;
		for(auto it=y2.begin();it!=y2.end();it++){
			sum+=*it;
			ans2++;
		}
		for(auto it=y1.begin();it!=y1.end();it++){
			sum+=*it;
			if(sum>0){
				ans2++;
			}else{
				break;
			}
		}
	}	
	
	if(!z2.empty()){
		ans3+=z0;
		int sum=0;
		for(auto it=z2.begin();it!=z2.end();it++){
			sum+=*it;
			ans3++;
		}
		for(auto it=z1.begin();it!=z1.end();it++){
			sum+=*it;
			if(sum>0){
				ans3++;
			}else{
				break;
			}
		}
	}	
	int ans=max(ans3,max(ans1,ans2));
	if(ans==0){
		cout<<-1;
	}else{
		cout<<ans;
	}
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号