40分求助!!!

P3958 [NOIP2017 提高组] 奶酪

算距离的时候平方炸`int`了,改成`long long`就过了 ```cpp #include<bits/stdc++.h> #define N 5005 using namespace std; struct xx{double x,y,z;}a[N]; int k,n,i,j,tot,q[N],vis[N],head[N],son[N],nxt[N]; double h,r; inline void add(int x,int y){son[++tot]=y;nxt[tot]=head[x];head[x]=tot;} inline bool dist(int i,int j){ long long xx=(a[i].x-a[j].x)*(a[i].x-a[j].x); long long yy=(a[i].y-a[j].y)*(a[i].y-a[j].y); long long zz=(a[i].z-a[j].z)*(a[i].z-a[j].z); return (xx+yy+zz)<=4ll*r*r; } int main(){ scanf("%d",&k); while(k--){ scanf("%d%lf%lf",&n,&h,&r); tot=0; for(i=0;i<=n+1;i++)head[i]=vis[i]=0; for(i=1;i<=n;i++){ scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].z); if(a[i].z<=r)add(0,i),add(i,0); if(a[i].z+r>=h)add(i,n+1),add(n+1,i); } for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) if(dist(i,j))add(i,j),add(j,i); int h=1,t=1,flag=0;q[1]=0;vis[0]=1; while(h<=t){ int x=q[h]; for(i=head[x];i;i=nxt[i]){ int v=son[i]; if(vis[v])continue; if(v==n+1){flag=1;break;} q[++t]=v;vis[v]=1; } if(flag)break;h++; } if(flag)printf("Yes\n"); else printf("No\n"); } } ```
by libohan0905 @ 2022-11-12 09:24:35


@[libohan0905](/user/205125) 为什么还是40分呢?
by louzhengzhe2009 @ 2022-11-18 18:49:19


可以过的,仔细看我给的代码,**把你的`dist`函数里的`4.0`改为`4LL`就好了,注意数字也要开`long long`** @[louzhengzhe2009](/user/770104)
by libohan0905 @ 2022-11-20 13:22:09


[评测记录](https://www.luogu.com.cn/record/94769300)
by libohan0905 @ 2022-11-20 13:22:45


@[libohan0905](/user/205125) 那咋回事? [评测记录](https://www.luogu.com.cn/record/94846234)
by louzhengzhe2009 @ 2022-11-20 20:00:18


别开O2就A了
by libohan0905 @ 2022-11-20 20:05:39


貌似把$N$开大(比如$100005$)开O2也能A
by libohan0905 @ 2022-11-20 20:07:22


@[louzhengzhe2009](/user/770104)
by libohan0905 @ 2022-11-20 20:10:05


@[libohan0905](/user/205125) 谢谢!没开O2过了!
by louzhengzhe2009 @ 2022-11-20 21:17:59


@[libohan0905](/user/205125) 不过为什么开了O2只有40分呢?
by louzhengzhe2009 @ 2022-11-20 21:18:36


| 下一页