QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#415233 | #4886. Best Sun | do_while_true | WA | 32ms | 5868kb | C++20 | 4.6kb | 2024-05-20 16:32:39 | 2024-05-20 16:32:39 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<ctime>
#include<random>
#include<array>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
mt19937 rnd(0);
struct pt{
ll x,y;
pt(ll a=0,ll b=0){x=a;y=b;}
pt operator+(pt z){return pt(x+z.x,y+z.y);}
pt operator-(pt z){return pt(x-z.x,y-z.y);}
};
ll Cross(pt a,pt b){return a.x*b.y-a.y*b.x;}
ll dot(pt a,pt b){return a.x*b.x+a.y*b.y;}
bool sign(pt a){
return (a.y>0)||(a.y==0&&a.x>0);
}
bool operator<(pt a,pt b){
if(a.x==0&&a.y==0)return 0;
if(b.x==0&&b.y==0)return 1;
return sign(a)==sign(b)?Cross(a,b)>0:sign(a);
}
pt Z(pt a){
return pt(-a.y,a.x);
}
const int N=310;
const ld inf=1e6;
const ld eps=1e-9;
int n;
pt a[N];
ld dis[N][N],val[N][N];
int ok[N][N],id[N][N],pos[N];
vpii eg;
ld Sum(int x,int y,int z){
return abs(Cross(a[z]-a[x],a[y]-a[x]))*0.5;
}
void init(int o){
for(int i=1;i<=n;i++)pos[i]=0;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)ok[i][j]=0;
vi vec;
for(int i=1;i<=n;i++)if(sign(a[i]-a[o]))vec.pb(i);
sort(vec.begin(),vec.end(),[&](int &x,int &y){return a[x]-a[o]<a[y]-a[o];});
int len=vec.size();
for(int i=0;i<len;i++)pos[vec[i]]=i+1;
for(auto i:vec){
int p=0;
for(int j=1;j<=n;j++)if(id[i][j]==o)p=j;
int pre=0;
for(int j=p-1;j>=1;j--){
int x=id[i][j];
if(pos[x]&&pos[x]>pos[i]){
if(pre==0 || pos[x]<pos[pre]){
pre=x;
ok[i][x]=1;
}
}
}
for(int j=n;j>p;j--){
int x=id[i][j];
if(pos[x]&&pos[x]>pos[i]){
if(pre==0 || pos[x]<pos[pre]){
pre=x;
ok[i][x]=1;
}
}
}
}
// for(int i=1;i<=n;i++,cerr<<'\n')
// for(int j=1;j<=n;j++){
// fprintf(stderr,"ok[%d][%d] = %d\n",i,j,ok[i][j]);
// }
// cerr<<'\n';
}
ld dp[N];
const ld INF=1e12;
int check(int o,ld mid){
for(int i=1;i<=n;i++)dp[i]=-INF;
for(auto [i,j]:eg){
if((i==o||pos[i]) && (j==o||pos[j])){
if(ok[i][j]){
if(dp[i]!=-inf){
cmax(dp[j],dp[i]+Sum(o,i,j)-mid*val[i][j]);
}
}
else if(i==o){
cmax(dp[j],-mid*val[i][j]);
}
else if(j==o){
cmax(dp[j],dp[i]-mid*val[i][j]);
}
}
}
ld s=dp[o];
for(int i=1;i<=n;i++)s-=mid*dis[o][i];
return s>=0;
}
void solve(){
read(n);
for(int i=1;i<=n;i++)read(a[i].x,a[i].y);
// shuffle(a+1,a+n+1,rnd);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)id[i][j]=j;
sort(id[i]+1,id[i]+n+1,[&](int x,int y){return a[x]-a[i]<a[y]-a[i];});
}
vpii().swap(eg);
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i!=j)eg.pb(i,j);
sort(eg.begin(),eg.end(),[&](pii x,pii y){return a[x.se]-a[x.fi]<a[y.se]-a[y.fi];});
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)val[i][j]=dis[i][j]=sqrtl(dot(a[i]-a[j],a[i]-a[j]));
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i!=j){
for(int k=1;k<=n;k++){
if(Cross(a[k]-a[i],a[j]-a[i])>0 && dot(a[k]-a[i],a[j]-a[i])>=0 && dot(a[k]-a[j],a[i]-a[j])>=0)
val[i][j]+=min(dis[i][k],dis[j][k]);
if(Z(a[k]-a[i])<a[j]-a[i])
val[i][j]+=dis[i][k];
if(Z(a[k]-a[j])<a[j]-a[i])
val[i][j]-=dis[j][k];
}
// fprintf(stderr,"val[%d][%d] = %.5lf\n",i,j,val[i][j]);
}
ld l=0;
for(int o=1;o<=n;o++){
init(o);
if(check(o,l+eps)){
ld r=inf,mid;
for(int i=1;i<=50;i++){
mid=(l+r)/2;
if(check(o,mid))l=mid;
else r=mid;
}
l=(l+r)/2;
}
}
printf("%.10lf\n",l);
}
signed main(){
#ifdef do_while_true
assert(freopen("data.in","r",stdin));
// assert(freopen("data.out","w",stdout));
#endif
int T;read(T);
while(T--)solve();
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3916kb
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.3090169947 1.2368614279 0.2711375417 1.5631002093
result:
ok 4 numbers
Test #2:
score: 0
Accepted
time: 28ms
memory: 3824kb
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.0873983540 18268.5193616723 102489.9883902619 66685.7544280801 18674.6579374142 106468.9651319726 14427.0246510714 29966.2453025431 143547.7510835876 13097.1756881260 162410.1683169807 72070.9324178750 29369.9926278870 52867.2944311013 90314.3083467568 99775.9271965681 144449.7053083693 64406....
result:
ok 10000 numbers
Test #3:
score: 0
Accepted
time: 18ms
memory: 5868kb
input:
10000 3 2 2 2 -2 -5 -5 3 -3 5 5 -4 2 -2 3 -4 1 2 -2 -4 4 3 1 -4 2 1 -4 1 3 2 1 -1 1 -3 3 3 4 5 3 -1 -3 -3 3 1 5 5 0 5 -1 3 2 -3 -5 -3 5 3 3 -4 4 0 -5 5 4 3 2 -3 5 0 2 -5 3 -2 -3 5 -3 5 4 3 -1 4 4 4 4 3 3 5 3 -1 4 2 -1 3 2 -3 4 3 -4 3 3 0 4 -2 -2 -1 -3 3 -2 0 -4 -2 4 2 3 -3 -1 3 1 1 -3 3 2 -5 2 3 -4 ...
output:
0.6507007009 0.2268090706 0.4946825665 0.8255326311 0.2675324748 0.7379284566 0.1368529463 0.8277457959 1.3896281206 0.2484761663 1.0251262661 0.2252451217 0.7981688506 1.0521776335 0.2700907564 0.2210280035 0.6549291478 1.0657925462 0.1207361886 0.1727212129 0.4458825287 0.2484761663 0.1224985771 0...
result:
ok 10000 numbers
Test #4:
score: 0
Accepted
time: 31ms
memory: 3956kb
input:
5625 4 -405394 -381883 602267 -335687 -620806 984110 271283 531233 4 196903 -993060 290851 358123 -890076 -717709 -681138 209884 4 -849589 607722 -21517 -586295 208561 -220953 924518 622983 4 -832186 456270 289934 43656 636006 339718 188963 113907 4 -305762 -872205 -520125 368722 -774548 984204 4245...
output:
232625.0042744306 268175.8269859640 159589.3236305169 60440.7530425984 133893.1234363519 63201.9907486266 167697.6634061344 129470.0132843164 126903.8540728106 106643.9712630971 131692.3112279052 100421.0550162129 148490.2748179025 68842.2423098228 241376.1911161291 303904.5464356644 77462.333614780...
result:
ok 5625 numbers
Test #5:
score: -100
Wrong Answer
time: 32ms
memory: 3832kb
input:
5625 4 -2 -1 4 -5 -2 -4 -4 -4 4 -1 -5 4 4 2 -5 -5 1 4 -3 -4 -3 -1 -5 -1 4 -2 4 -2 4 -4 1 -1 -1 5 -4 4 -3 -5 -1 4 5 -1 3 5 4 -4 -2 1 4 -1 1 3 4 4 -5 3 -3 3 5 -4 -1 4 4 1 2 2 -5 1 0 0 -3 4 -5 -4 2 -3 5 3 -3 2 4 2 -2 -4 3 1 -4 -5 -5 4 -3 5 -2 4 1 3 1 -4 4 0 -5 5 -5 0 -2 -3 2 4 0 5 -1 -4 -2 0 4 -1 4 4 -...
output:
0.4434837799 1.6080239367 0.6764635638 0.8146821262 1.5727954037 0.2020448020 0.4423673056 0.3055832125 1.5089069101 1.3227875241 0.5218559494 0.3982804500 1.2194946257 1.1774912556 1.3951026933 1.0737731264 0.7540897905 0.6075591088 1.4373192208 0.9671123461 0.9534878420 1.4836242817 1.2273730219 0...
result:
wrong answer 1st numbers differ - expected: '0.4919682', found: '0.4434838', error = '0.0484844'