本题的难点主要在于如何判定上确界和下确界。
题目给了已经降序排好序的成绩,让我们分别输出金、银、铜奖的上确界和下确界。
根据题意可知上确界是最后一名获得该奖的选手的成绩,下确界则是比最后一名获得该奖的选手后一名的成绩高一点。
按照这样可以写出代码如下:
#include<bits/stdc++.h>
using namespace std;
struct node{
int x;//通过的题数
int y;//总罚时
}a[100005];
int main(){
int g,s,b,h,n;
cin>>g>>s>>b>>h;
for(int i=1;i<=g+s+b+h;i++){
cin>>a[i].x>>a[i].y;
}
cout<<a[g].x<<" "<<a[g].y<<" "<<a[g+1].x<<" "<<a[g+1].y-1<<endl;//金牌上下确界
cout<<a[g+s].x<<" "<<a[g+s].y<<" "<<a[g+s+1].x<<" "<<a[g+s+1].y-1<<endl;//银牌上下确界
cout<<a[g+s+b].x<<" "<<a[g+s+b].y<<" "<<a[g+s+b+1].x<<" "<<a[g+s+b+1].y-1<<endl;//铜牌上下确界
return 0;
}但会发现当最后一名获得该奖的选手后一名的罚时为 时按照上面把下确界总罚时减一,会输出 ,所以不对。
那就要讨论最后一名获得该奖的选手后一名的罚时为 时的下确界,既然总罚时已经是 了,那么我没就可以把通过的题数变多,也就是 ,让后再考虑总罚时。
既然通过的题数已经 了,那么总罚时就得是最大罚时,根据题意可知最多能答 次,设通过的题数为 次,因为要通过 道题,那么就至少得有 次提交通过,但提交通过不加罚时所以就可以得 次罚时,每次罚时都加二十分钟,因此可得 分钟的罚时,因为每道题的基础罚时是从比赛开始到该题通过的时间,所以只需要 道题都在第 分钟通过就能再得 分钟罚时,所以总罚时为 分钟,即 分钟。
代码
#include<bits/stdc++.h>
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) x/gcd(x,y)*y
#define ll long long
#define ull unsigned long long
#define un unsigened
using namespace std;
struct node{
int x,y;
}a[100005];
bool cmp(node xx,node yy){
if(xx.x==yy.x){
return xx.y<yy.y;
}
return xx.x>yy.x;
}
int main(){
int g,s,b,h,n;
cin>>g>>s>>b>>h;
n=g+s+b+h;
for(int i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;
}
//sort(a+1,a+n+1,cmp);
cout<<a[g].x<<" "<<a[g].y<<" ";//金奖上确界
if(a[g+1].y==0){
cout<<a[g+1].x+1<<" "<<a[g+1].x*279+180279<<endl;//金奖最后一名的后一名的罚时为0的情况
}else{
cout<<a[g+1].x<<" "<<a[g+1].y-1<<endl;
}
cout<<a[g+s].x<<" "<<a[g+s].y<<" ";//银奖上确界
if(a[g+s+1].y==0){
cout<<a[g+s+1].x+1<<" "<<a[g+s+1].x*279+180279<<endl;//银奖最后一名的后一名的罚时为0的情况
}else{
cout<<a[g+s+1].x<<" "<<a[g+s+1].y-1<<endl;
}
cout<<a[g+s+b].x<<" "<<a[g+s+b].y<<" ";//铜奖上确界
if(a[g+s+b+1].y==0){
cout<<a[g+s+b+1].x+1<<" "<<a[g+s+b+1].x*279+180279<<endl;//铜奖最后一名的后一名的罚时为0的情况
}else{
cout<<a[g+s+b+1].x<<" "<<a[g+s+b+1].y-1<<endl;
}
return 0;
}