hdu-1392 Surround the Trees poj Rope (简单凸包)
hdu : http://acm.hdu.edu.cn/showproblem.php?pid=1392
题意:给你n个数的坐标,用一根绳子把它们围起来,问你需要多长的绳子?
(当数的个数为2时特判 即两点的距离,这是因为一条直线不应再回去围了)
题解:简单的凸包;
code:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
#define eps 1e-6
int top , n;
//点
struct POINT
{double x, y;POINT(){ }POINT(double a, double b){x = a;y = b;}
}p[105],st[105];
//线段
struct Seg
{POINT a, b;Seg() { }Seg(POINT x, POINT y){a = x;b = y;}
};
//叉乘
double cross(POINT o, POINT a, POINT b)
{return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);
}//多边形面积,需要有顺序,顺(逆)时针。double area()
{double ans = 0;for(int i = 1; i < top; i ++){ans += cross(p[0], p[i], p[i + 1]);}return ans;
}
//找凸包基点排序
bool cmp0(POINT a, POINT b)
{if(a.y < b.y) return true;else if(a.y == b.y && a.x < b.x) return true;return false;
}
double dis(POINT a,POINT b){return sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) );
}
//极角排序
bool cmp1(POINT a, POINT b)
{if(cross(p[0], a, b) > eps) return true;else if(fabs(cross(p[0], a, b)) < eps && dis(p[0], a) - dis(p[0], b) > eps) return true;return false;
}
//Graham_scan 求凸包.所求为纯净凸包...
void Graham_scan()
{sort(p, p + n, cmp0);sort(p + 1, p + n, cmp1);top = 0;p[n] = p[0];st[top ++] = p[0]; st[top ++] = p[1];for(int i = 2; i <= n; i ++){while(top > 2 && (cross(st[top - 1], st[top - 2], p[i]) > eps || fabs(cross(st[top - 1], st[top - 2], p[i])) < eps)) top --;st[top ++] = p[i];}top --;
}int main(){while(scanf("%d",&n),n){for(int i = 0;i < n;i++)scanf("%lf %lf",&p[i].x,&p[i].y);if(n == 2) {printf("%.2lf\n",dis(p[0],p[1]));continue;}Graham_scan();double sumd = 0;for(int i = 0;i < top;i++)sumd += dis(st[i],st[i+1]);printf("%.2lf\n",sumd);}
}
poj : http://poj.org/problem?id=2365
题意:类似于上题,不过会多加一个圆的周长,因为绳子是绕圆柱的围成多边形后即多了一个圆的周长;
hdu-1392 Surround the Trees poj Rope (简单凸包)相关推荐
- hdu 1392 Surround the Trees
凸包模板 #include<cstdio> #include<cstring> #include<iostream> #include<string> ...
- 1392 - Surround the Trees
凸包裸题. #include<cstdio> #include<cstring> #include<iostream> #include<vector> ...
- Unity Mecanim动画系统 之 动画混合树(Blend Trees)的简单使用
Unity Mecanim动画系统 之 动画混合树(Blend Trees)的简单使用 目录 Unity Mecanim动画系统 之 动画混合树(Blend Trees)的简单使用 一.简单介绍 二. ...
- hdu 5273 Dylans loves sequence 逆序数简单递推
Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
- 【解题报告】【HDOJ1392】【Graham凸包】Surround the Trees
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 典型凸包 1.当只有一个点时 输出时0.00 2.当只有两个点时 输出时两个点的距离 3.当n& ...
- HDU 1432 Lining Up (POJ 1118)
枚举,枚举点 复杂度为n^3. 还能够枚举边的,n*n*log(n). POJ 1118 要推断0退出. #include<cstdio> #include<cstring> ...
- POJ 2135 简单费用流
题意: 题意是一个人他要从牧场1走到牧场n然后在走回来,每条路径只走一次,问全程的最短路径是多少. 思路: 这个题目挺简单的吧,首先要保证每条边只能走一次,然后还要要求费用最 ...
- poj 3920(简单dp)
题意:从起点每次最多跳s步,最多跳t次,从起点到终点的最大得分. 解题思路:dp[i][j]表示第i次跳到位置j的最大得分.简单的动态规划. #include<iostream> #inc ...
- poj 3280(简单区间dp)
题意:将一个字符串转换成回文串的最小花费. 解题思路:简单的区间dp,dp[i][j]表示从i到j的字符串转换成回文串的最小化费. #include<iostream> #include& ...
最新文章
- iis 无法连接mysql_远程无法连接SQL2000及MySQL的原因和解决办法
- mysql 子分区_MySQL子分区一例
- 【2021年度训练联盟热身训练赛第二场】g2g c u l8r(python)
- python模块之序列化模块
- python3 写文件时指定文件名_Python3基础 os listdir 列举指定的所有文件及文件夹的名字...
- 解决软件安装中出现checking for FUSE... no方法一例
- 查询DBA_HIST_ACTIVE_SESS_HISTORY缓慢
- Flink 1.14 新特性预览
- 逻辑回归之ROC曲线的绘制
- html怎么置顶图像,css怎么固定图片位置不变?
- Word——从任意页开始设置页码的方法
- 如何提升固定资产盘点效率
- Python和R的GUI图形化编程与用户界面
- 强化学习实践七:给Agent添加记忆功能
- 蓝牙hid协议源码解析
- Python数据分析练习:北京、广州PM2.5空气质量分析(1)
- Docker上手系列:Docker入门hello world
- 预装Win10改Win7出错了?这些失误一定不要犯!
- Electron从入门到精通
- 互联网日报 | 9月20日 星期日 | 全国共享单车注册用户超4亿;小米今年科研投入超100亿元;苹果股价跌入“技术性熊市”...