题解:P6614 蛋糕 Cake

题目传送门:P6614 蛋糕 Cake

思路:

根据题目,我们可以得知 \(1\leq k\leq10^{12}\)

当我们的一次函数斜率足够大时,可以把这条直线当作是平行于 \(y\) 轴的。

所以我们这里可以取到 \(k = 10^{12}\)

然后,我们就要让直线的左上侧有 \(\dfrac{n \times a}{a+b}\) 个点,

让直线的右下侧有 \(\dfrac{n \times b}{a+b}\) 个点。

我们先把坐标点拿结构体存起来,

struct node{
	int x,y;
}p[100010];

为了满足我们上面的需求,

可以将 \(x\) 作为第一关键字从小到大排,

\(y\) 作为第二关键字从大到小排。

来保证前 \(\dfrac{n \times a}{a+b}\) 个点在左上侧。

bool cmp(node a,node b){
    if (a.x!=b.x)return a.x<b.x;
    return a.y>b.y;
}

我们最后输出第 \(a\) 个点的信息即可

AC代码:

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

struct node{
	int x,y;
}p[100010];

bool cmp(node a,node b){
    if (a.x!=b.x)return a.x<b.x;
    return a.y>b.y;
}

int main(){
	// freopen("text.in","r",stdin);
	// freopen("text.out","w",stdout);
	ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
    int n,a,b;cin>>n>>a>>b;
    for (int i=1;i<=n;i++)cin>>p[i].x>>p[i].y;
    sort(p+1,p+n+1,cmp);
    cout<<1000000000000<<' '<<p[n/(a+b)*a].x<<' '<<p[n/(a+b)*a].y;
	return 0;
}
posted @ 2024-12-17 14:09  Zheng_iii  阅读(14)  评论(0)    收藏  举报