QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#648648 | #4886. Best Sun | rotcar07 | TL | 1ms | 4396kb | C++23 | 3.1kb | 2024-10-17 19:47:55 | 2024-10-17 19:47:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
struct vec{
ll x,y;
vec(ll _x=0, ll _y=0):x(_x),y(_y){}
inline vec operator + (const vec&other)const{return vec(x+other.x,y+other.y);}
inline vec operator - (const vec&other)const{return vec(x-other.x,y-other.y);}
inline db operator ^ (const vec&other)const{return x*other.y-y*other.x;}
};
inline db sq(db w){return w*w;}
inline db len(const vec&x){return sqrt(sq(x.x)+sq(x.y));}
inline db ang(const vec&x){return atan2(x.y,x.x);}
mt19937 rnd(time(0));
constexpr db eps=1e-8,pi=acos(-1);
inline db anh(const vec&x){
db w=ang(x);
if(w<0) w+=2*pi;
return w;
}
inline db sb(const db&x){if(x<0)return x+2*pi;else return x;}
inline bool chkrt(vec A,vec B,vec C){return ((B-A)^(C-A))<0;}
constexpr int maxn=305;
int n,id[maxn];
vec p[maxn];
bool f[maxn][maxn];
db dis[maxn][maxn],ag[maxn][maxn],ct[maxn][maxn];
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
vector<pii> seg;
db dp[maxn];
inline bool chk(int d,db ans){
for(int i=1;i<=n;i++) dp[i]=-1e18;
dp[d]=0;
db anss=-1e18;
for(auto x:seg){
int u=x.fi,v=x.se;
if(!f[u][v]) continue;
db res=dp[u];
res+=((p[d]-p[u])^(p[u]-p[v]))-ans*ct[u][v];
if(v==d) anss=max(anss,res);
else dp[v]=max(dp[v],res);
}
for(int i=1;i<=n;i++) anss-=ans*dis[d][i];
return anss>=0;
}
inline db ff(db w){
if(w<-pi/2) w+=2*pi;
return w;
}
inline void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>p[i].x>>p[i].y;
sort(p+1,p+n+1,[=](const vec&x,const vec&y){return x.y==y.y?x.x<y.x:x.y<y.y;});
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dis[i][j]=len(p[i]-p[j]),
ag[i][j]=ang(p[i]-p[j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
if(i==j) continue;
seg.push_back(mp(i,j));
vec A=p[i],B=p[j];
vec t=B-A;swap(t.x,t.y);t.y=-t.y;
ct[i][j]=dis[i][j];
db w=ff(ang(t));
for(int k=1;k<=n;k++){
if(ff(ag[k][i])<w) ct[i][j]+=dis[i][k];
if(ff(ag[k][j])<=w) ct[i][j]-=dis[j][k];
if(k!=i&&k!=j&&chkrt(A,B,p[k])&&!chkrt(A,A+t,p[k])&&!chkrt(B,p[k],B+t))
ct[i][j]+=min(dis[i][k],dis[j][k]);
}
}
sort(seg.begin(),seg.end(),[=](const pii&x,const pii&y){return sb(ag[x.second][x.first])<sb(ag[y.second][y.first]);});
db ans=0;
for(int i=1;i<=n;i++) id[i]=i;shuffle(id+1,id+n+1,rnd);
for(int dd=1;dd<=n;dd++){
int d=id[dd];
vector<int>v;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f[i][j]=0;
for(int i=d+1;i<=n;i++) v.push_back(i),f[d][i]=f[i][d]=1;
sort(v.begin(),v.end(),[=](int x,int y){return ag[x][d]<ag[y][d];});
int w=n-d;for(int i=0;i<w;i++){
vec chichi(0,0);
for(int j=i+1;j<w;j++){
int a=v[i],b=v[j];
if((chichi^(p[b]-p[a]))>=0){
chichi=p[b]-p[a];
f[a][b]=f[b][a]=1;
}
}
}
if(!chk(d,ans)) continue;
db l=ans,r=1e6;
while(fabs(r-l)>eps){
db mid=(l+r)/2;
if(chk(d,mid)) l=ans=mid,l+=eps;
else r=mid-eps;
}
}
cout<<fixed<<setprecision(10)<<ans/2<<'\n';
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t;cin>>t;
while(t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4396kb
input:
4 3 -1 -1 1 -1 0 1 4 0 0 10 0 0 10 8 1 5 2 0 -2 0 1 1 -1 1 0 3 8 4 4 -4 4 4 -4 -4 -4 5 6 -6 5 -5 -6 6 -5
output:
0.3090169919 1.2368614172 0.2711375323 1.5631002078
result:
ok 4 numbers
Test #2:
score: -100
Time Limit Exceeded
input:
10000 3 702262 828158 -350821 -420883 -466450 13507 3 28647 -193498 126436 -864937 -287798 738936 3 270358 -269567 745815 -485408 834083 677952 3 -2036 -403634 742978 -263774 975937 -609237 3 584248 -472620 482016 -356760 284902 903881 3 -292004 504925 -935756 373793 -781101 -434659 3 -858513 684433...
output:
85789.0873983503 18268.5193616645 102489.9883902576 66685.7544280751 18674.6579374056 106468.9651319639 14427.0246510653 29966.2453025418 143547.7510835859 13097.1756881261 162410.1683169794 72070.9324178692 29369.9926278732 52867.2944310916 90314.3083467452 99775.9271965576 144449.7053083588 64406....