关于long long和int数据运算的疑问
查看原帖
关于long long和int数据运算的疑问
401840
StarsWhisper楼主2021/4/15 22:02

题目中给出了n h r t的范围,不会超过int,但是这几个变量用int就80分WA了,用longlong就AC。

记得以前学c的时候学过longlong和int运算应该会强制转换成longlong运算的,为什么会出错呢?

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <set>
typedef long long int LL;
const int N = 1e3+5;
LL n,h,r,t;
int sset[N];
struct Pos
{
    LL x,y,z;
}pos[N];
bool jjjj(Pos a,Pos b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z) <= 4*r*r;
}

int ffind(int x)
{
    return sset[x] == x ? x : sset[x] = ffind(sset[x]);
}
void mmerge(int x,int y)
{
    sset[ffind(x)] = ffind(y);
}
int main()
{
    //freopen("D:\\EdgeDownloadPlace\\P3958_9.in","r",stdin);
    scanf("%lld",&t);
    while(t--){
        for(int i=0; i<N; i++) sset[i] = i;
        scanf("%lld%lld%lld",&n,&h,&r);
        for(int i=1; i<=n; i++){
            scanf("%lld%lld%lld",&pos[i].x,&pos[i].y,&pos[i].z);
            if(pos[i].z-r <= 0) mmerge(i,n+1);
            if(pos[i].z+r >= h) mmerge(i,n+2);
            for(int j=1; j<i; j++){
                if(jjjj(pos[i],pos[j])){
                    mmerge(i,j);
                }
            }
        }
        printf(ffind(n+1)==ffind(n+2) ? "Yes\n" : "No\n");
    }
    return 0;
}

2021/4/15 22:02
加载中...