题目
(个人向)一道可以用分割区间和区间合并解决的的题,但我没这么做
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;
}