QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#744241 | #8082. Minimum Euclidean Distance | yhddd | WA | 1ms | 3940kb | C++14 | 1.8kb | 2024-11-13 21:16:42 | 2024-11-13 21:16:43 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<db,db>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=200010;
const int inf=1e18;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
return x*f;
}
bool Mbe;
int n,q;
pii a[maxn];
db cross(pii u,pii v){return u.fi*v.se-u.se*v.fi;}
db mul(pii u,pii v){return u.fi*v.fi-u.se*v.se;}
pii operator-(pii u,pii v){return {u.fi-v.fi,u.se-v.se};}
db dis(pii u,pii v){return sqrtl((u.fi-v.fi)*(u.fi-v.fi)+(u.se-v.se)*(u.se-v.se));}
db dis(pii u,pii v,pii w){
db x=v.fi,y=v.se,xx=w.fi,yy=w.se;
db aa=yy-y,bb=x-xx,cc=xx*y-x*yy;
// cout<<(aa*x+bb*y+cc==0)<<" "<<(aa*xx+bb*yy+cc==0)<<"\n";
db d=abs(aa*u.fi+bb*u.se+cc)/sqrtl(aa*aa+bb*bb);
// cout<<x<<" "<<y<<" "<<xx<<" "<<yy<<" "<<d<<" "<<dis(u,v)<<" "<<dis(u,w)<<"\n";
if(mul(u-w,v-w)<0||mul(u-v,w-v)<0)return min(dis(u,v),dis(u,w));
return d;
}
void work(){
n=read();q=read();
for(int i=1;i<=n;i++)a[i]={read(),read()};a[n+1]=a[1];
while(q--){
pii b={read(),read()},c={read(),read()};
pii o={(b.fi+c.fi)/2,(b.se+c.se)/2};
db r=dis(o,b);
// cout<<r<<"\n";
db ans=inf;
for(int i=1;i<=n;i++){
ans=min(ans,dis(o,a[i],a[i+1]));
}
bool fl=1;
for(int i=1;i<=n;i++)if(cross(a[i+1]-a[i],o-a[i])<0)fl=0;
if(fl)ans=0;
// cout<<ans<<"\n";
printf("%.10lf\n",r*r/2+ans*ans);
}
}
// \
444
bool Med;
int T;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
T=1;
while(T--)work();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3940kb
input:
4 3 0 0 1 0 1 1 0 1 0 0 1 1 1 1 2 2 1 1 2 3
output:
0.2500000000 0.7500000000 1.8750000000
result:
ok Your answer is acceptable!^ ^
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3872kb
input:
48 10 -30 0 -29 -4 -28 -7 -27 -9 -25 -12 -22 -16 -21 -17 -17 -20 -14 -22 -12 -23 -9 -24 -5 -25 -4 -25 0 -24 3 -23 5 -22 8 -20 12 -17 13 -16 16 -12 18 -9 19 -7 20 -4 21 0 21 1 20 5 19 8 18 10 16 13 13 17 12 18 8 21 5 23 3 24 0 25 -4 26 -5 26 -9 25 -12 24 -14 23 -17 21 -21 18 -22 17 -25 13 -27 10 -28 ...
output:
589.5000000000 52.0000000000 1051.2500000000 66.6250000000 174.3750000000 307.3850000000 272.8750000000 287.8750000000 689.6250000000 436.2500000000
result:
wrong answer Except 51.470588235300, but found 52.000000000000!QAQ