题目链接:http://codeforces.com/gym/101164/attachments

题意:对于已知的 n 个二维坐标点,要求按照某种特定的连线方式将尽可能多的点连接(任意相邻的 3 个点 a , b , c ,点 c 必须在有向线段 ab 的左侧。问最多可以连多少点,并给出连线顺序。

思路:因为连接最多的点,尽量让形成一个凸包将点包起来,形成螺旋式的连接所有的点,凸包模板;

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stdlib.h>
#include<time.h>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define bug(x) cout<<"bug"<<x<<endl; const int N=1e5+,M=1e6+,inf=;
const LL INF=1e18+,mod=;
const double eps = 1e-;
const double PI = acos(-1.0);
int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
struct Point
{
double x,y;
int pos;
Point() {}
Point(double _x,double _y)
{
x = _x;
y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x,y - b.y);
}
//叉积
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
//点积
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
} }a[N];
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
int n;
const int MAXN = ;
Point listt[MAXN];
int Stack[MAXN],top,vis[N]; //相对于listt[0]的极角排序
vector<int>ans;
bool _cmp(Point p1,Point p2)
{
double tmp = (p1-listt[])^(p2-listt[]);
if(sgn(tmp) > )return true;
else if(sgn(tmp) == && sgn(dist(p1,listt[]) - dist(p2,listt[])) <= ) return true;
else return false;
}
void Graham()
{
Point p0;
int k = ;
p0 = listt[]; //找最下边的一个点
for(int i = ; i < n; i++)
{
if( (p0.y > listt[i].y) || (p0.y == listt[i].y && p0.x > listt[i].x) )
{
p0 = listt[i];
k = i;
}
}
swap(listt[k],listt[]);
sort(listt+,listt+n,_cmp);
int m=;
Stack[] = ;
Stack[] = ;
vis[]=;
vis[]=;
top = ;
while(top<n)
{
for(int i = ; i < n; i++)
{
if(vis[i])continue;
while(top > && sgn((listt[Stack[top-]]-listt[Stack[top-]])^(listt[i]-listt[Stack[top-]])) <= )
top--,vis[Stack[top]]=;
Stack[top++] = i;
vis[i]=;
}
}
}
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%lf%lf",&listt[i].x,&listt[i].y),listt[i].pos=i+;
Graham();
printf("%d\n",n);
for(int i=;i<n;i++)
printf("%d ",listt[Stack[i]].pos);
return ;
}
/*
5
0 4
3 0
7 11
9 1
13 8
*/

gym 101164 H.Pub crawl 凸包的更多相关文章

  1. 【计算几何】【凸包】Gym - 101164H - Pub crawl

    平面上n个点,点之间沿直线走,规划一条路线,每次只能往左半平面的点走,走过最多的点. 显然所有的点都能走过. n^2的暴力显然是每次找左边与其所形成夹角最小的点,但这样过不了(卡常数?). 或者每轮不 ...

  2. codeforces Gym 100187H H. Mysterious Photos 水题

    H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  3. codeforces Gym 100500H H. ICPC Quest 水题

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  4. Codeforces Gym 100114 H. Milestones 离线树状数组

    H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...

  5. [GYM 100492A] Average Convex Hull 凸包好题

    大致题意: 给出一个点集,其中有一个点有相同的几率会被删除,求删除之后的点集够成的凸包上的点的平均数. 首先看到题目,可以考虑枚举删除的点,将其凸包上前后两点以及两点间凸包内所有点构建凸包,因为凸包内 ...

  6. Gym - 101147H H. Commandos —— DP

    题目链接:http://codeforces.com/gym/101147/problem/H 题解: 单纯的三维DP.可用递推或记忆化搜索实现. 学习:开始时用记忆化搜索写,dp[]初始化为0,结果 ...

  7. Gym 100952 H. Special Palindrome

    http://codeforces.com/gym/100952/problem/H H. Special Palindrome time limit per test 1 second memory ...

  8. Codeforces Gym 100425H H - Football Bets 构造

    H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  9. codeforces gym 100357 H (DP 高精度)

    题目大意 有r*s张扑克牌,数字从1到 r,每种数字有s种颜色. 询问对于所有随机的d张牌,能选出c张组成顺子的概率和组成同花的概率. 解题分析 对于组成顺子的概率,令dp[i][j][k]表示一共选 ...

随机推荐

  1. hud3007 Buried memory

    题目链接 最小圆覆盖 并不知道为什么是O(n)的,而且要随机化点的顺序 #include<algorithm> #include<iostream> #include<c ...

  2. Autel MaxiSys Elite Diagnostic Tool Common problem solving methods

    1. updating MaxiFlash Elite to firmware 3.21? My maxisys communicate with the MaxiFlash J2534 but Ma ...

  3. linux系统Centos环境下搭建SVN服务器及权限配置

    linux系统Centos环境下如何搭建SVN服务器以及svnserve.conf.authz.passwd配置文件详细介绍   至于svn的概念,这里就不做详细阐述了,可以自行百度.简单来讲就是一个 ...

  4. 垂直打击之JVM剖析

    让Java应用程序运行是一回事,但让他们跑得快就是另外一回事了.在面对对象的环境中,性能问题就像来势凶猛的野兽.但JVM的复杂性将性能调整的复杂程度增加了一个级别.这里Refcard涵盖了JVM in ...

  5. 数据库-MySQL入门

    什么是数据库? 一定方式储存在一起.能与多个用户共享.具有尽可能小的冗余度.与应用程序彼此独立的数据集合 数据库管理系统(简称DBMS):是为管理数据库而设计的电脑软件系统,一般具有存储.截取.安全保 ...

  6. Python进阶【第二篇】编写Python代码

    一.第一句Python代码——Hello Word 在 /home/dev/ 目录下创建 hello.py 文件,内容如下: print "hello,world" 执行 hell ...

  7. ES6知识整理(5)--对象的扩展

    个人开这个公众号的初心是为了积累知识,因此并没有做什么推广,再说自己也不知道怎么推广,推广之后又能干些什么.已经将近10天没发文章了,虽然每天都加班,但也不会一点时间都没有,有时还是会懒癌发作不想学习 ...

  8. Spring AOP(基于代理类的AOP实现)

    #基于代理类的AOP实现:step1: 1 package com.sjl.factorybean; /**切面类*/ import org.aopalliance.intercept.MethodI ...

  9. java321 面向对象编程

  10. EDK II之驱动程序与硬件平台的初始化简介

    本文旨在简单介绍一下UEFI中驱动程序的加载方式(这里涉及的模块指的是符合UEFI Driver Model的模块): 在UEFI中,当一个驱动模块被加载时,在模块入口点只会安装EFI_DRIVER_ ...