题解:P12034 [USTCPC 2025] Introduction to ICPC
题目传送门
本题的难点主要在于如何判定上确界和下确界。
题目给了已经降序排好序的成绩,让我们分别输出金、银、铜奖的上确界和下确界。
根据题意可知上确界是最后一名获得该奖的选手的成绩,下确界则是比最后一名获得该奖的选手后一名的成绩高一点。
按照这样可以写出代码如下:
#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;
}