题解 P5485 【[JLOI2010]铁人双项比赛】
并不会半平面交。
考虑二分答案ans,即第一名领先第二名的时间。
首先将速度的单位从
对于二分的答案
只有
当
当
当
若k有解,则此
题面并没有说,但是应该是在有多种方案时输出
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
int read()
{
int x = 0;
int f = 1;
char ch = getchar();
for(;!isdigit(ch);ch = getchar())
if(ch == '-')
f = -1;
for(;isdigit(ch);ch = getchar())
x = x * 10 + (ch ^ 48);
return x * f;
}
void print(int x)
{
if(x < 0)
putchar('-'),x = -x;
char ch = x % 10 + '0';
if(x > 9)
print(x / 10);
putchar(ch);
}
const int N = 150;
double t1[N],t2[N],s;
int n;
bool check(double ans)
{
double maxx = s,minn = 0;
for(int i = 1;i < n;i++)
{
double l = t1[i] - t2[i],r = ans - s * t2[i];
if(t1[i] == t2[i])
if(r > 0)
return false;
if(t1[i] > t2[i])
minn = max(minn,r / l);
if(t1[i] < t2[i])
maxx = min(maxx,r / l);
}
return maxx > minn;
}
void P(double ans)
{
double minn = 0;
for(int i = 1;i < n;i++)
{
double l = t1[i] - t2[i],r = ans - s * t2[i];
if(t1[i] > t2[i])
minn = max(minn,r / l);
}
printf("%.2lf %.2lf %.0lf\n",minn,s - minn,ans);
}
int main()
{
freopen("1.in","r",stdin);
s = read(),n = read();
for(int i = 1;i <= n;i++)
{
scanf("%lf %lf",&t1[i],&t2[i]);
t1[i] = 3600 / t1[i],t2[i] = 3600 / t2[i];
}
for(int i = 1;i < n;i++)
t1[i] -= t1[n],t2[i] -= t2[n];
double l = -1,r = 1e50;
while(r - l >= 0.01)
{
double mid = (l + r) / 2;
if(check(mid))
l = mid;
else
r = mid;
}
if(r < 0)
puts("NO");
else
P(r);
}