QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109972 | #5570. Epidemic Escape | 2024zll | WA | 1ms | 7072kb | C++14 | 4.8kb | 2023-05-31 08:49:12 | 2023-05-31 08:49:17 |
Judging History
answer
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
namespace IO{
const int ARR_SIZE=1<<20;
#define gc() ((IO::si!=IO::ti||(IO::ti=(IO::si=IO::input)+fread(IO::input,1,IO::ARR_SIZE,stdin))),IO::si!=IO::ti?*(IO::si++):EOF)
char input[ARR_SIZE],*si=input,*ti=input;
template<typename T>
void read(T&num){
bool flag=true;
int ch=gc();
num=0;
while(ch<48||ch>57){
if(ch=='-')flag=false;
ch=gc();
}
while(ch>=48&&ch<=57)num=num*10+(ch^48),ch=gc();
flag||(num=-num);
}
}
using IO::read;
typedef long double real;
const int maxn=100000,maxk=5;
const real eps=1e-16;
int n,q;
struct Vector{
real x,y;
Vector(const real x=0,const real y=0):x(x),y(y){}
friend bool operator<(const Vector&A,const Vector&B){
return A.x!=B.x?A.x<B.x:A.y<B.y;
}
friend Vector operator-(const Vector&A,const Vector&B){
return Vector(A.x-B.x,A.y-B.y);
}
friend Vector operator/(const Vector&A,const real&x){
return Vector(A.x/x,A.y/x);
}
friend real Cross(const Vector&A,const Vector&B){
return A.x*B.y-A.y*B.x;
}
friend real Dot(const Vector&A,const Vector&B){
return A.x*B.x+A.y*B.y;
}
}P[maxn],Q;
bool used[maxn];
std::vector<int>down[maxk],up[maxk],stack;
void PolygonToConvex(std::vector<int>&down,std::vector<int>&up,std::vector<int>&stack){
int end=n-1;
while(end>=0&&used[end])end--;
// printf("end = %d\n",end);
if(end==-1)return;
stack.resize(n*2);
int top=-1;
for(int i=0;i<=end;i++){
if(used[i])continue;
while(top>0&&Cross(P[stack[top]]-P[stack[top-1]],P[i]-P[stack[top]])<0)top--;
stack[++top]=i;
}
const int k=top;
for(int i=end-1;i>=0;i--){
if(used[i])continue;
while(top>k&&Cross(P[stack[top]]-P[stack[top-1]],P[i]-P[stack[top]])<0)top--;
stack[++top]=i;
}
stack.resize(top+1);
//printf("top = %d\n",top);
for(int i:stack)used[i]=true/*,printf("%d ",i)*/;
//printf("\n");//for debugging
down.assign(stack.begin(),stack.begin()+k+1);
if(k<top)up.assign(stack.begin()+k+1,stack.begin()+top+1);
}
int k;
struct CMP{
bool operator()(const int x,const int y)const{
return Dot(P[x],Q)>Dot(P[y],Q);
}
}cmp;
std::priority_queue<int,std::vector<int>,CMP>queue;
int vis[maxn],now_id;
void push(const int x){
// printf("push(x = %d)\n",x);
if(vis[x]==now_id||Dot(P[x],Q)<=eps)return;
vis[x]=now_id;
queue.push(x);
if((int)queue.size()>k)/*printf("pop: %d\n",queue.top()),*/queue.pop();
}
void solve(std::vector<int>&vec,const bool flag){
/*printf("vec:");
for(int i:vec)printf(" %d",i);
printf("\n");//for debugging*/
// for(int i:vec)push(i);//for debugging
// return;//for debugging
if((int)vec.size()<=k)
for(int i:vec)
push(i);
else{
for(int i=0;i<k;i++)push(vec[i]);
for(int i=(int)vec.size()-k;i<(int)vec.size();i++)push(vec[i]);
int l=0,r=vec.size()-2,mid;
if(flag)
while(l<r){
mid=(l+r)>>1;
if(Cross(Q-P[vec[mid]],P[vec[mid+1]]-P[vec[mid]])>0)r=mid;
else l=mid+1;
}
else
while(l<r){
mid=(l+r)>>1;
if(Cross(Q-P[vec[mid]],P[vec[mid+1]]-P[vec[mid]])>0)l=mid+1;
else r=mid;
}
if(n==100)printf("vec[l = %d] = %d\n",l,vec[l]);
for(int i=std::max(0,l-k),lim=std::min((int)vec.size()-1,l+k);i<=lim;i++)push(vec[i]);
}
}
int main(){
read(n);
for(int i=0;i<n;i++)read(P[i].x),read(P[i].y),P[i]=P[i]/Dot(P[i],P[i]);
std::sort(P,P+n);
// for(int i=0;i<n;i++)printf("%lf %lf %d\n",P[i].x,P[i].y,i);
for(int i=0;i<maxk;i++)PolygonToConvex(down[i],up[i],stack);
/*if(n==100){
puts("up:");
for(int i=0;i<maxk;i++){
for(int j:up[i])printf("%d ",j);
putchar('\n');
}
puts("down:");
for(int i=0;i<maxk;i++){
for(int j:down[i])printf("%d ",j);
putchar('\n');
}
}*/
/*
up:
98 95 59 31 11 2 1 0
96 92 74 42 18 3
91 84 68 49 32 12 6 5 4
87 82 70 60 41 37 30 15 10 8 7
88 73 52 27 26 19 16 14 13
down:
0 35 39 66 99
3 9 28 51 63 97
4 24 40 64 90 94
7 21 29 47 58 86 93
13 23 36 46 62 79 85 89
*/
for(int i:up[0])
printf("%Lf %Lf\n",P[i].x,P[i].y);
read(q);
memset(vis,-1,sizeof(int)*n);
for(int i=0,x,y;i<q;i++){
now_id=i;
// printf("- - - i = %d - - -\n",i);
read(x),read(y),read(k);
if(x==0&&y==0){
puts("-1");
continue;
}
Q=Vector(x,y);
Q=Q/sqrtl(Dot(Q,Q));//sqrtl !!!
// printf("Q = (%lf, %lf)\n",Q.x,Q.y);
while(!queue.empty())queue.pop();
for(int j=0;j<k;j++)solve(down[j],y>0);
for(int j=0;j<k;j++)solve(up[j],y<0);
if((int)queue.size()<k){
puts("-1");
continue;
}
const int u=queue.top();
// printf("u = %d\n",u);
const real dot=Dot(P[u],Q);
// printf("dot = %lf\n",dot);
const real ans=(real)Dot(Q,Q)/dot/2;
printf("%.10Lf\n",ans);
if(n==100)printf("i_%d_k_%d_P%d_%Lf_%Lf_Q_%Lf_%Lf_dot_%Lf\n",i,k,u,P[u].x,P[u].y,Q.x,Q.y,dot);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7072kb
input:
5 5 -3 5 4 -6 2 -5 0 4 1 2 -3 -10 1 6 -9 1
output:
0.121951 0.097561 -0.150000 0.050000 -0.200000 0.000000 8.7002554241 3.2260195623
result:
wrong answer 1st numbers differ - expected: '8.7002554', found: '0.1219510', error = '0.9859831'