跳到正文

题解

P3691 妖精大战争 Sol

zgaius约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年6月13日
收录
2026年6月14日
更新
2026年11月6日
篇幅
约 2 分钟
题目
P3691

版本

  1. v3当前
  2. v2
  3. v1

不是,某谷是 AI 测试平台吗,怎么还有神经网络???

思路简述

一个不用半点随机的办法,正确率较低,但基本在 90% 90\% 以上:

不难发现,离两者中心点距离远近的界限大致是一条直线,故看与两个中心点的欧氏距离哪个更近即可。

当然,在这里可以不开根,精度损失稍微少一点。

评测记录

https://www.luogu.com.cn/record/281611389

AC code

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m,t;cin>>n>>m>>t;
    double sx1=0,sy1=0,c1=0,sx2=0,sy2=0,c2=0,x,y;
    int k;
    for(int i=0;i<n;i++){
        cin>>x>>y>>k;
        if(k==1)sx1+=x,sy1+=y,c1++;
        else sx2+=x,sy2+=y,c2++;
    }
    double cx1=sx1/c1,cy1=sy1/c1,cx2=sx2/c2,cy2=sy2/c2;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        double d1=(x-cx1)*(x-cx1)+(y-cy1)*(y-cy1);
        double d2=(x-cx2)*(x-cx2)+(y-cy2)*(y-cy2);
        cout<<(d1<d2?"1\n":"-1\n");
    }
    return 0;
}
原文