Constellation CodeForces - 618C

题目传送门

题意:在一个平面直角坐标系当中给你n个点,然后选择其中的三个点要求这个三角形里面没有其他的点。

思路:如果要三角形没有其他的的点,其实只要将所有的点排一个序然后再找这个三角形,按照x从小到大排序,如果x相同的话,按照y坐标从小到大,然后判断这三个点不共线就可以找到这个三角形了。

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define MAXN 100010
#define INF 10000000
#define MOD 1000000007
#define LL long long

using namespace std;

struct Node {
  LL x;
  LL y;
  int id;
} point[MAXN];

bool cmp(const Node &x1, const Node &x2) {
  if (x1.x == x2.x)
    return x1.y < x2.y;
  return x1.x < x2.x;
}

int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> point[i].x >> point[i].y;
    point[i].id = i + 1;
  }
  sort(point, point + n, cmp);
  for (int i = 2; i < n; ++i) {
    if ((point[i].x - point[0].x) * (point[i].y - point[1].y) !=
        (point[i].x - point[1].x) * (point[i].y - point[0].y)) {
      cout << point[0].id << " " << point[1].id << " " << point[i].id << endl;
      break;
    }
  }
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值