第一反应是在凸包上随便找一条边,然后找剩下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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers

    题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...

  4. codeforces Educational Codeforces Round 16-E(DP)

    题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. replication factor

    http://www.tuicool.com/articles/RJbIBj 关于Hadoop中replication factor解惑 时间 2014-06-09 08:00:50   ITeye ...

  2. include和 merge

    include和merge标记的作用主要是为了解决layout的重用问题. 比如我们有三四个Activity但是他们都要用到同一个样式的标题栏,虽然我们把一样的代码copy个三四遍也没关系,但实在是太 ...

  3. 如果更新包更新包现场,class文件更新过去,没有改变,及时删掉,照样能进那个模块的问题。

    这是打更新包需要注意的问题: 带$的同名文件也需要copy过来打更新包,不能只更新一个class文件,找了1天的错误,简直日乐购.

  4. background和background-position相关笔记

    background 可在一个声明中设置background-color,background-image,background-repeat,background-attachment,backgr ...

  5. Lua基础(一)

    1.Lua中有8个基本类型分别为:nil.boolean.number.string.userdata.function.thread和table 2.Lua中的表达式包括数字常量.字符串常量.变量. ...

  6. 关于tag,viewWithTag

    iOS SDK内置了一套搜寻机制,可通过tag来查找子视图. **苹果公司很少给子视图设置tag.笔者所知范围的唯一例外出现在UIAlertView中,该类会给按钮分别设置值为1.2的标签 viewW ...

  7. c++模板入门

    最近使用了c++模板,觉得非常强大,只是写起来需要掌握一点技巧.大部分模板都是直接把定义写在.h头文件,并且有些人还说这样做的原因是模板不支持分编译,可是以前的编译器对模板的支持不够好吧,但是现在完全 ...

  8. Alamofire 框架浅析

    下面是 Github 主页上对 Alamofire 的描述 Elegant HTTP Networking in Swift 为什么这次我选择阅读 Alamofire 的源代码而不是 AFNetwor ...

  9. mapreduce 依赖组合

    mport java.io.IOException;import java.util.StringTokenizer; import org.apache.hadoop.conf.Configurat ...

  10. Java 向Hbase表插入数据报(org.apache.hadoop.hbase.client.HTablePool$PooledHTable cannot be cast to org.apac

    org.apache.hadoop.hbase.client.HTablePool$PooledHTable cannot be cast to org.apac 代码: //1.create HTa ...