Gym - 100741J Empty Circle

Gym - 100741J

S集合中有n个点,是否存在三个点构成三角形的外接圆,且S集合的所有点都不在外接圆内

这样的三角形有很多种情况,所以任找一点 a ,找到其距离最近的点 b , 然后遍历其他的点 i ,找到 ∠aib最小的点,它们构成的三角形外接圆一定是满足条件的。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <bitset>
#define INF 0x3f3f3f3f
#define eps 1e-6
#define PI 3.1415926
#define mod 1000000007
#define base 2333
using namespace std;
typedef long long LL;
const int inf = 1e9;
const int maxn = 1e6 + 10;
const int maxx = 7e5 + 10;
inline void splay(int &v) {
    v=0;char c=0;int p=1;
    while(c<'0' || c >'9'){if(c=='-')p=-1;c=getchar();}
    while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
    v*=p;
}
int n, x[maxn], y[maxn];

int dis(int i, int j) {
    return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}

int line(int i, int j, int k) {
    if((y[k]-y[i])*(x[j]-x[i]) == (y[j]-y[i])*(x[k]-x[i]))
        return 1;
    return 0;
}

void solve() {
    splay(n);
    for(int i = 1; i <= n; i++)
        splay(x[i]), splay(y[i]);
    int a = 1, b = 0, c = 0, aa, bb, cc = 1e9;
    for(int i = 2; i <= n; i++) {
        if(dis(a, i) <= cc) {
            cc = dis(a, i);
            b = i;
        }
    }
    double co, xx = 1e9;
    for(int i = 2; i <= n; i++) {
        if(i == b) continue;
        if(line(a, b, i)) continue;
        aa = dis(b, i), bb = dis(a, i);
        co = (aa+bb-cc)/(2.0*sqrt(aa)*sqrt(bb));
        if(xx > co)
            xx = co, c = i;
    }
    if(c) printf("Yes\n%d %d %d\n", a, b, c);
    else printf("No\n");
}

int main() {
    //srand(time(NULL));
    //freopen("kingdom.in","r",stdin);
    //freopen("kingdom.out","w",stdout);
    solve();
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值