QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104226 | #6401. Classic: N Real DNA Pots | beckham_of_laiwu | TL | 2ms | 5648kb | C++14 | 1.8kb | 2023-05-09 17:18:06 | 2023-05-09 17:18:09 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL long long
const int N = 1e5;
struct qwq{
double x,y;
};
qwq p[N];
int n,k,cnt;
double a[N],b[N],q[N];
double ans;
bool cmp(qwq a,qwq b)
{
if(a.y != b.y) return a.x < b.x;
return a.y < b.y;
}
void find(double h,int l,int r)
{
if(l == r)
{
q[l] = h;
return;
}
int mid = (l + r) / 2;
if(h < q[mid])
find(h,l,mid);
else find(h,mid + 1,r);
}
bool check(double slp)
{
if(slp != 0)
for(int i = 1;i <= n;i ++)
{
//p[i].y = abs(slp * a[i] - b[i]) / sqrt(1.0 + (b[i] / a[i]) * (b[i] / a[i]));
//p[i].x = sqrt(a[i] * a[i] + b[i] * b[i] - p[i].y * p[i].y);
p[i].y = -slp * a[i] + b[i];
p[i].x = a[i];
}
else
for(int i = 1;i <= n;i ++)
{
p[i].x = a[i];
p[i].y = b[i];
}
//sort(p + 1,p + n + 1,cmp);
cnt = 0;
q[0] = -1e9;
for(int i = 1;i <= n;i ++)
{
//printf("p[%d].y = %lf ",i,p[i].y);
if(p[i].y >= q[cnt]) q[++ cnt] = p[i].y;
else find(p[i].y,1,cnt);
}
/*cout << "height: ";
for(int i = 1;i <= cnt;i ++)
printf("%lf ",q[i]);
cout << "; cnt = " << cnt << endl;*/
return cnt >= k;
}
int main()
{
scanf("%d%d",&n,&k);
for(int i = 1;i <= n;i ++)
scanf("%lf%lf",&a[i],&b[i]);
double l = -1e9, r = 1e9;
while(r - l >= 1e-6)
{
double mid = (l + r) / 2;
//cout << l << " " << r << " " << mid << endl;
if(check(mid))
{
ans = mid;
l = mid;
}
else r = mid;
}
l = (int)ans - 3;
r = (int)ans + 3;
while(r - l >= 1e-6)
{
double mid = (l + r) / 2;
//cout << l << " " << r << " " << mid << endl;
if(check(mid))
{
ans = mid;
l = mid;
}
else r = mid;
}
//cout << check(-1.0) << endl;;
cout << ans;
return (0 ^ 0);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5648kb
input:
4 3 1 2 2 4 3 3 4 1
output:
-1
result:
ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'
Test #2:
score: 0
Accepted
time: 2ms
memory: 5524kb
input:
2 2 1 1 5 3
output:
0.5
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #3:
score: -100
Time Limit Exceeded
input:
2 2 222640995 547139825 489207317 725361095