9.24 网易雷火笔试

第二题 ac

#include <bits/stdc++.h>
using namespace std;
struct user{
    float x,y;
    int b;
    int c;
};
struct area{
    int type;
    float dx,dy,dx1,dy1;
    float cx,cy,cr;
    bool inArea(user a){
        if(type == 0){
            if(sqrt((a.x - cx) * (a.x - cx) + (a.y - cy) * (a.y - cy)) <= cr) return true;
        }else{
            if(a.x >= dx && a.x <= dx1 && a.y >= dy && a.y <= dy1)return true;
        }
        return false;
    }
};

bool q2out(user q2,vector<area> a){
    for(area s : a){
        if(s.inArea(q2)) return true;
    }
    return false;
}
bool q1q2in(user q1,user q2,vector<area> a){
    unordered_set<int> us;
    for(int i = 0;i < a.size(); ++i){
        if(a[i].inArea(q1)) us.insert(i);
    } 
    for(int i = 0;i < a.size(); ++i){
        if(a[i].inArea(q2) && us.count(i)){
            return true;
        } 
    } 
    return false;
}
int main() {
    int n,m,q;
    cin>>n>>m>>q;
    float x,y,b,c;
    int type;
    float dx,dy;
    float cx,cy,cr;
    int q1,q2;
    vector<user> t(n);
    vector<area> a(m);
    for(int i = 0;i < n;++i){
        cin>>x>>y>>b>>c;
        t[i].x = x;
        t[i].y = y;
        t[i].b = b;
        t[i].c = c;
    }
    for(int i = 0;i < m;++i){
        cin>>type;
        a[i].type = type;
        if(type == 1){//矩形
            for(int j = 0;j < 4;++j){
                cin>>dx>>dy;
                 a[i].dx = a[i].dx > dx ? dx : a[i].dx;
                 a[i].dy = a[i].dy > dy ? dy : a[i].dy;
                 a[i].dx1 = a[i].dx1 < dx ? dx : a[i].dx1;
                 a[i].dy1 = a[i].dy1 < dy ? dy : a[i].dy1;
            }
        }else if(type == 0){//圆形
            cin>>cx>>cy>>cr;
            a[i].cx = cx;
            a[i].cy = cy;
            a[i].cr = cr;
        }
    }
    
    for(int i = 0;i < q;++i){
        cin>>q1>>q2;
        if(t[q1 - 1].c == t[q2 - 1].c){
            if(t[q2 - 1].b != 1)cout<<1<<endl;//q2有隐身buff
            else cout<<0<<endl;//q2没有隐身buff,在草内或草外q1都可以看见
        }else{
            if(t[q2 - 1].b == 1){//q2有隐身buff
                cout<<0<<endl;
            }else{//q2没有隐身buff
                if(!q2out(t[q2 - 1],a)|| q1q2in(t[q2 - 1],t[q1 - 1],a))//q1,q2在同一草内 || q2在草外
                {
                    cout<<1<<endl;
                }else{
                    cout<<0<<endl;
                }
            }
        }
    }
}

全部评论

相关推荐

昨天 17:00
武汉大学 Java
6月了还有点击就送的offer吗😭,投麻了😢
叫我阿东就行:这个bg,也还没找到理想的工作吗?好难,好焦虑
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务