80分(最后两个大数据wa了)求助大佬

P3958 [NOIP2017 提高组] 奶酪

开$long\ long$救星了吧
by star_magic_young @ 2018-09-02 17:41:34


@[star_magic_young](/space/show?uid=38372) 大佬 发错代码了 这个才是 ```cpp #include<bits/stdc++.h> using namespace std; const int maxn=1000+5; int t,n,h,r,sign; bool mark[maxn]; unsigned long long judgedx,judgedy; struct cheese { int x,y,z; }c[maxn]; bool cmp(cheese x,cheese y) { return x.z<y.z; } bool judge(int a1,int b1,int c1,int a2,int b2,int c2) { judgedx=(a1-a2)*(a1-a2)+(b1-b2)*(b1-b2)+(c1-c2)*(c1-c2); judgedy=4*r*r; if(judgedx<=judgedy) return 1; return 0; } void dfs(int m) { if(c[m].z+r>=h) { sign=1; return; } for(int i=1;i<=n;i++) { if(mark[i]==1) continue; if(judge(c[m].x,c[m].y,c[m].z,c[i].x,c[i].y,c[i].z)==1) { mark[i]=1; dfs(i); } } } void work() { sort(c,c,cmp); for(int i=1;i<=n;i++) { if(c[i].z-r<=0) { mark[i]=1; dfs(i); mark[i]=0; if(sign==1) { printf("Yes\n"); return; } } } printf("No\n"); } int main() { scanf("%d",&t); for(int i=1;i<=t;i++) { sign=0; memset(mark,0,sizeof(mark)); scanf("%d%d%d",&n,&h,&r); for(int j=1;j<=n;j++) { scanf("%d%d%d",&c[j].x,&c[j].y,&c[j].z); } work(); } return 0; } ```
by DriverBen @ 2018-09-02 17:43:29


@[Driver笨](/space/show?uid=116303) 呃,你需要把所有都改成long long,不然精度会挂
by taoran @ 2018-09-02 17:52:27


``` // luogu-judger-enable-o2 #include<bits/stdc++.h> #define LL long long using namespace std; const int maxn=1000+5; long long t,n,h,r,sign; bool mark[maxn]; unsigned long long judgedx,judgedy; struct cheese { long long x,y,z; }c[maxn]; bool cmp(cheese x,cheese y) { return x.z<y.z; } bool judge(long long a1,long long b1,long long c1,long long a2,LL b2,LL c2) { judgedx=(a1-a2)*(a1-a2)+(b1-b2)*(b1-b2)+(c1-c2)*(c1-c2); judgedy=4LL*r*r; if(judgedx<=judgedy) return 1; return 0; } void dfs(int m) { if(c[m].z+r>=h) { sign=1; return; } for(int i=1;i<=n;i++) { if(mark[i]==1) continue; if(judge(c[m].x,c[m].y,c[m].z,c[i].x,c[i].y,c[i].z)==1) { mark[i]=1; dfs(i); } } } void work() { sort(c,c,cmp); for(int i=1;i<=n;i++) { if(c[i].z-r<=0) { mark[i]=1; dfs(i); mark[i]=0; if(sign==1) { printf("Yes\n"); return; } } } printf("No\n"); } int main() { scanf("%d",&t); for(int i=1;i<=t;i++) { sign=0; memset(mark,0,sizeof(mark)); scanf("%lld%lld%lld",&n,&h,&r); for(int j=1;j<=n;j++) { scanf("%lld%lld%lld",&c[j].x,&c[j].y,&c[j].z); } work(); } return 0; } ```@[Driver笨](/space/show?uid=116303)
by taoran @ 2018-09-02 17:52:47


就是虽然judgedx是long long但是默认几个int乘在一起是int所以还是爆int了
by taoran @ 2018-09-02 17:54:17


@[taoran](/space/show?uid=39223) 谢谢大佬
by DriverBen @ 2018-09-04 16:11:07


|