1015 德才论[PAT (Basic Level) Practice]

2 篇文章 0 订阅

题目

(个人向)一道可以用分割区间和区间合并解决的的题,但我没这么做

1015 德才论[PAT (Basic Level) Practice]
平台不知道为什么没有提供MarkDown,所以我截图一下.
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
学到tuple就用tuple,巧了不是(bushi

CODE

//给个免费的赞吧谢谢ヽ( ̄ω ̄( ̄ω ̄〃)ゝ
#include<bits/stdc++.h>
using namespace std;
int n,l,h;
bool cmp(tuple<bool,int,int,int,int>t1,tuple<bool,int,int,int,int>t2){
	int a=get<4>(t1);int b=get<4>(t2);//总分 
	int c=get<2>(t1);int d=get<2>(t2);//德分 
	int e=get<1>(t1);int f=get<1>(t2);//准考证号 
	
	if(a==b&&d==c)return e<f;
	else if(a==b)return c>d;
	else return a>b;
}

int main(){
	cin>>n>>l>>h;
	vector<tuple<bool,int,int,int,int>>v;
	int count=0;
	for(int i=0;i<n;++i){
		int a,b,c;cin>>a>>b>>c;
		if(!(b<l||c<l||b>100||c>100)){
			++count;
			v.push_back(make_tuple(true,a,b,c,b+c));
		}
	}
	sort(v.begin(),v.end(),cmp);
	cout<<count<<endl;
	for(int i=0;i<count;++i){
		bool whether=get<0>(v[i]);int de=get<2>(v[i]);int cai=get<3>(v[i]);
		if(de>=h&&cai>=h&&whether){
			get<0>(v[i])=false; 
			cout<<get<1>(v[i])<<" "<<get<2>(v[i])<<" "<<get<3>(v[i])<<endl;
		}
	}
	for(int i=0;i<count;++i){
		bool whether=get<0>(v[i]);int de=get<2>(v[i]);int cai=get<3>(v[i]);
		if(de>=h&&cai<h&&whether){
			get<0>(v[i])=false; 
			cout<<get<1>(v[i])<<" "<<get<2>(v[i])<<" "<<get<3>(v[i])<<endl;
		}
	}
	for(int i=0;i<count;++i){
		bool whether=get<0>(v[i]);int de=get<2>(v[i]);int cai=get<3>(v[i]);
		if(de>=cai&&whether){
			get<0>(v[i])=false; 
			cout<<get<1>(v[i])<<" "<<get<2>(v[i])<<" "<<get<3>(v[i])<<endl;
		}
	}
	for(int i=0;i<count;++i){
		bool whether=get<0>(v[i]);int de=get<2>(v[i]);int cai=get<3>(v[i]);
		if(whether){
			get<0>(v[i])=false; 
			cout<<get<1>(v[i])<<" "<<get<2>(v[i])<<" "<<get<3>(v[i])<<endl;
		}
	}
//	for(auto x:v)cout<<get<1>(x)<<" "<<get<2>(x)<<" "<<get<3>(x)<<" "<<get<4>(x)<<endl; 
	return 0;
}

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值