gym 101164 H.Pub crawl 凸包
题目链接: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 凸包的更多相关文章
- 【计算几何】【凸包】Gym - 101164H - Pub crawl
平面上n个点,点之间沿直线走,规划一条路线,每次只能往左半平面的点走,走过最多的点. 显然所有的点都能走过. n^2的暴力显然是每次找左边与其所形成夹角最小的点,但这样过不了(卡常数?). 或者每轮不 ...
- codeforces Gym 100187H H. Mysterious Photos 水题
H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...
- codeforces Gym 100500H H. ICPC Quest 水题
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- Codeforces Gym 100114 H. Milestones 离线树状数组
H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...
- [GYM 100492A] Average Convex Hull 凸包好题
大致题意: 给出一个点集,其中有一个点有相同的几率会被删除,求删除之后的点集够成的凸包上的点的平均数. 首先看到题目,可以考虑枚举删除的点,将其凸包上前后两点以及两点间凸包内所有点构建凸包,因为凸包内 ...
- Gym - 101147H H. Commandos —— DP
题目链接:http://codeforces.com/gym/101147/problem/H 题解: 单纯的三维DP.可用递推或记忆化搜索实现. 学习:开始时用记忆化搜索写,dp[]初始化为0,结果 ...
- Gym 100952 H. Special Palindrome
http://codeforces.com/gym/100952/problem/H H. Special Palindrome time limit per test 1 second memory ...
- Codeforces Gym 100425H H - Football Bets 构造
H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- codeforces gym 100357 H (DP 高精度)
题目大意 有r*s张扑克牌,数字从1到 r,每种数字有s种颜色. 询问对于所有随机的d张牌,能选出c张组成顺子的概率和组成同花的概率. 解题分析 对于组成顺子的概率,令dp[i][j][k]表示一共选 ...
随机推荐
- Python3自定义日志类 mylog
#encoding=utf-8 import os, sysimport datetimeimport time class Mylog(object): # 根文件夹 root_dir = s ...
- Hadoop HA方案调研
原文成文于去年(2012.7.30),已然过去了一年,很多信息也许已经过时,不保证正确,与Hadoop学习笔记系列一样仅为留做提醒. ----- 针对现有的所有Hadoop HA方案进行调研,以时间为 ...
- easyui dialog 和 dategrid相关设置与应用
1 dialog一些参数 可以进行文件上传等操作closed:true:定义初始状态为关闭:modal:true:对话框被打开时,会有一个modal-mask,使得对话框底部的内容被一个层覆盖,不 ...
- Django form choices, placeholder
item=CharField(max_length=20,min_length=1,required=True,widget=widgets.TextInput({'placeholder':'tes ...
- java.lang.NoClassDefFoundError: org/apache/curator/RetryPolicy解决方法
今天集成es-job到公司的框架时,启动时出现上述错误 java.lang.NoClassDefFoundError: org/apache/curator/RetryPolicy at storm. ...
- ReentrantLock$Sync.tryRelease java.lang.IllegalMonitorStateException
早上一来,例行性的看主要环境的运行情况,发现有个环境中有如下异常: 17-02-28 08:13:37.368 ERROR pool-2-thread-65 com.ld.net.spider.Spi ...
- 【题解】Luogu CF915E Physical Education Lessons
原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...
- 第三周作业HAproxy文件操作
#coding:utf-8 #Author:Mr Zhi """ HAproxy配置文件操作: 1. 根据用户输入输出对应的backend下的server信息 2. 可添 ...
- Babel总结
什么是babel? babel是一个JavaScript编译器. Babel是一个工具链,主要用于将ECMAScript 2015+代码转换为向后兼容的旧浏览器或环境中JavaScript版本. 注解 ...
- Jbarcode 条形码生成工具
一.准备jar包 https://sourceforge.net/projects/jbcode/?source=typ_redirect 二.编写工具类 package com.example.de ...