Description
Input
Output
Sample Input
6 15698 17433
112412868 636515040
122123982 526131695
58758943 343718480
447544052 640491230
162809501 315494932
870543506 895723090
Sample Output
193409386/235911335
Data Constraint
.
.
.
.
.
.
.
分析
把所有点按照P/Q斜率投射到y轴上排序,可以证明相邻的点对应的线段一定有一条是最优解,因为不相邻的点与给定的斜率夹角比相邻的大
.
.
.
.
.
.
程序:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
double p,q,x,y,t=2147483647;
struct edge
{
double x,y,b;
}a[200010];
bool cmp(edge x,edge y)
{
return x.b<y.b;
}
long long gcd(long long x,long long y)
{
if (y==0) return x; else return gcd(y,x%y);
}
int main()
{
freopen("slope.in","r",stdin);
freopen("slope.out","w",stdout);
scanf("%d%lf%lf",&n,&p,&q);
double ans=p/q;
for (int i=1;i<=n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
a[i].b=a[i].y-p/q*a[i].x;
}
sort(a+1,a+n+1,cmp);
for (int i=1;i<=n-1;i++)
{
double w=(a[i].y-a[i+1].y)/(a[i].x-a[i+1].x);
if (abs(w-ans)<t)
{
t=abs(w-ans);
x=abs(a[i].x-a[i+1].x);
y=abs(a[i].y-a[i+1].y);
}
}
long long ansx=(long long)x,ansy=(long long)y;
long long g=gcd(ansx,ansy);
ansx/=g;
ansy/=g;
printf("%lld/%lld",ansy,ansx);
fclose(stdin);
fclose(stdout);
return 0;
}