QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#104227 | #6401. Classic: N Real DNA Pots | beckham_of_laiwu | WA | 2ms | 5680kb | C++14 | 1.8kb | 2023-05-09 17:19:11 | 2023-05-09 17:19:12 |
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 = 1;
q[1] = p[1].y;
for(int i = 2;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);
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 5680kb
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: 0ms
memory: 5648kb
input:
2 2 1 1 5 3
output:
0.5
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 2ms
memory: 5600kb
input:
2 2 222640995 547139825 489207317 725361095
output:
0.668581
result:
ok found '0.6685810', expected '0.6685813', error '0.0000003'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
1000 20 545612 774435015 828317 212155588 5294705 85926095 5648835 764528941 6159263 570820268 7177330 744079287 8446124 162286636 8735551 586528841 9263030 524140841 9505706 636254627 12111352 182639083 12750780 238494418 13149143 913232250 13382784 11485121 13699797 414697815 14263990 423817548 15...
output:
3.79321
result:
ok found '3.7932100', expected '3.7932105', error '0.0000001'
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 5676kb
input:
1000 100 163505 684865289 2674260 837752883 2694530 150054425 2870791 236723512 3262597 800933455 3558503 905056977 4260872 45990808 4532415 268478572 5299228 546172100 6019224 12074540 6345109 747272172 6539452 449655551 7215852 676269961 9062989 769545718 9444242 874911191 10264016 341805234 10595...
output:
-1.86058
result:
wrong answer 1st numbers differ - expected: '-1.8605779', found: '-1.8605800', error = '0.0000011'