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 ...
随机推荐
- su -无反应
一.问题产生环境 CentOS 6.3 X64SecureCRT 7.0.0 英文版 二.问题具体描述 今天操作自己的一台Linux服务器时,突然su命令不好使了,敲入命令回车后,没有任何反应,不管是 ...
- bjective-C 中核心处理字符串的类是 NSString 与 NSMutableString
Objective-C 中核心处理字符串的类是 NSString 与 NSMutableString ,这两个类最大的区别就是NSString 创建赋值以后该字符串的内容与长度不能在动态的更改,除非重 ...
- slf4j(simple logging facade for java)
http://www.tuicool.com/articles/IfeUfq slf4j(simple logging facade for java)是Java的简单的日志门面,它 不是具体的日 ...
- CodeForces 719B Anatoly and Cockroaches 思维锻炼题
题目大意:有一排蟑螂,只有r和b两种颜色,你可以交换任意两只蟑螂的位置,或涂改一个蟑螂的颜色,使其变成r和b交互排列的形式.问做少的操作次数. 题目思路:更改后的队列只有两种形式:长度为n以r开头:长 ...
- Gym 100917L Liesbeth and the String 规律&&胡搞
题目: Description standard input/outputStatements Little Liesbeth likes to play with strings. Initiall ...
- Java中的五种单例模式实现方法
[代码] Java中的五种单例模式实现方法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 2 ...
- php薪资
2千的php程序员就是可以用cms,做一个小企业的门户网站. 3千的php程序员,可以自己写代码开发php软件,但是这样程序员写的代码非常混乱,通常只能写数千行代码的小软件,并且痛苦的完工. 4K的p ...
- java 缓冲流
english.txt The arrow missed the target. They rejected the union demand. Where does this road go to? ...
- springMVC下载文件前修改文件名字
很多时候,为了方便,下载文件其实就直接写了一个文件在服务器上面的路径,然后直接点击一个这个地址,浏览器就自然而然的开始下载了. 但是这次项目需要在文件下载之前修改文件的名字,也就是说,服务器上文件的名 ...
- EL表达式,保留小数点后两位
你遇到过页面显示小数有9.987870488E9这个吗? 这是因为没有保留小数的原因 有时候用js保留小数很麻烦的时候,可以用EL表达式 <fmt:formatNumber type=" ...