CodeForces 618C CodeForces 618C
第一反应是在凸包上随便找一条边,然后找剩下n-2个点里面距离这条边最短的一个点,这三点就构成了符合要求的三角形。。然而。。精度被卡死。
换种思路,随便找两个点P1,P2,找剩下n-2个点中哪一个点与P1,P2形成的三角形面积最小,这三点构成了符合要求的三角形,然而我没写。。
最终这样写的,按X,Y进行排序,相邻三个判断是否三点共线即可
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std; const int maxn=+;
vector<int>v[maxn];
struct point
{
int px,y;
int x;
int id;
}p[maxn];
int n;
int lshx[maxn]; bool cmp(const point&a,const point&b)
{
if(a.px==b.px) return a.y<b.y;
return a.px<b.px;
} bool cmp1(const point&a,const point&b)
{
return a.id<b.id;
} long long multiply(point sp,point ep,point op)
{
long long a=(long long)(sp.px-op.px);
long long b=(long long)(ep.y-op.y);
long long c=(long long)(ep.px-op.px);
long long d=(long long)(sp.y-op.y); return a*b-c*d;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&p[i].px,&p[i].y);
p[i].id=i;
}
sort(p+,p++n,cmp);
int tot=;
p[].x=tot;
for(int i=;i<=n;i++)
{
if(p[i].px==p[i-].px) p[i].x=p[i-].x;
else
{
tot++;
p[i].x=tot;
}
} for(int i=;i<=n;i++) v[p[i].x].push_back(p[i].id);
sort(p+,p++n,cmp1);
if(v[].size()>=)
{
printf("%d %d ",v[][],v[][]);
printf("%d\n",v[][]);
}
else if(v[].size()>=)
{
printf("%d ",v[][]);
printf("%d %d\n",v[][],v[][]);
}
else
{
for(int i=;i<=tot;i++)
{
if(v[i].size()>=)
{
printf("%d ",v[i-][]);
printf("%d %d\n",v[i][],v[i][]);
break;
}
else
{
if(multiply(p[v[i][]],p[v[i-][]],p[v[i-][]])==) continue;
else
{
printf("%d %d %d\n",v[i][],v[i-][],v[i-][]);
break;
}
}
}
}
return ;
}
CodeForces 618C CodeForces 618C的更多相关文章
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers
题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...
- codeforces Educational Codeforces Round 16-E(DP)
题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...
- Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph
E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...
- Codeforces Educational Codeforces Round 15 D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Educational Codeforces Round 15 C. Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学
E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...
- Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法
D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...
随机推荐
- git 创建分支,删除分支,管理分支
参考 http://blog.csdn.net/dijason/article/details/9042425 查看分支: 1 查看本地分支: $ git branch 2 查看远程分支 $ g ...
- virt
www.itwhy.org/linux/debian7-%E5%AE%89%E8%A3%85-kvm-%E8%99%9A%E6%8B%9F%E6%9C%BA.html www.storageonlin ...
- junit 单元测试 - 参数化测试
junit4.x版本需要引入如下jar包: hamcrest-core-1.3.jar junit-4.12-beta-3.jar 新建一个计算器类,如下: package com.pt; publi ...
- (转)Unity3D移动平台动态读取外部文件全解析
Unity3D移动平台动态读取外部文件全解析 c#语言规范 阅读目录 前言: 假如我想在editor里动态读取文件 移动平台的资源路径问题 移动平台读取外部文件的方法 补充: 回到目录 前言: 一直有 ...
- AI 人工智能 探索 (九)
链接:http://pan.baidu.com/s/1c0AM3g0 密码:uccw 今天补充 创建物体 移动物体 ,当点击创建后 ,会出来一个 上图的 ui,他跟随 物体,当你把物体拖动到 指定的地 ...
- js数组总结
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- javascript语句语义大全(5)
1. var str = "abcd";alert(str.length);alert(str.charAt(0));//获取下标为0的字符alert(str.charCodeAt ...
- andorid 自定义view属性declare-styleable
1. reference:参考某一资源ID. (1)属性定义: <declare-styleable name = "名称"> <attr name = &quo ...
- 多校 Babelfish
题目链接:http://acm.hust.edu.cn/vjudge/contest/124435#problem/A 密码:acm Sample Input dog ogday cat atcay ...
- PAT (Advanced Level) 1100. Mars Numbers (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...