hdu 1348 (凸包求周长)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348
Wall
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3229 Accepted Submission(s): 919
Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.
The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm> using namespace std; const int MAX=;
const double eps=1e-; typedef struct point
{
double x,y;
}point; point c[MAX];
int top; bool dy(double x,double y)
{
return x>y+eps;
}
bool xy(double x,double y)
{
return x<y-eps;
}
bool xyd(double x,double y)
{
return x<y+eps;
}
bool dyd(double x,double y)
{
return x>y-eps;
}
bool dd(double x,double y)
{
return fabs(x-y)<eps;
} double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
}
double dist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} bool cmp(point a,point b)
{
if(dd(a.y,b.y))
{
return xy(a.x,b.x);
}
return xy(a.y,b.y);
}
bool cmp1(point a,point b)
{
double len=crossProduct(c[],a,b);
if(dd(len,0.0))
{
return xy(dist(c[],a),dist(c[],b));
}
return xy(len,0.0);
} point stk[MAX]; double dis()
{
double sum=0.0;
for(int i=;i<top;i++)
{
sum+=dist(stk[i],stk[i+]);
}
sum+=dist(stk[top],stk[]);
return sum;
} double Graham(int n)
{
sort(c,c+n,cmp);
sort(c+,c+n,cmp1);
top=;
stk[top++]=c[];
stk[top++]=c[];
stk[top++]=c[];
top--;
for(int i=;i<n;i++)
{
while()
{
point a,b;
a=stk[top];
b=stk[top-];
if(xyd(crossProduct(a,b,c[i]),0.0))
{
top--;
}
else
break;
}
stk[++top]=c[i];
}
return dis();
} int main()
{
int i,j,k,t;
int n,m;
int cas=;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
{
scanf("%lf%lf",&c[i].x,&c[i].y);
}
if(cas++)
{
printf("\n");
}
double re=*acos(0.0)*m;
double sum=Graham(n);
printf("%.0lf\n",sum+re);
}
}
hdu 1348 (凸包求周长)的更多相关文章
- HDU - 1392 凸包求周长(模板题)【Andrew】
<题目链接> 题目大意: 给出一些点,让你求出将这些点全部围住需要的多长的绳子. Andrew算法 #include<iostream> #include<cstdio& ...
- TZOJ 2569 Wooden Fence(凸包求周长)
描述 Did you ever wonder what happens to your money when you deposit them to a bank account? All banks ...
- zoj 1453 Surround the Trees(凸包求周长)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds Memory ...
- hdu 1348 凸包模板
http://acm.hdu.edu.cn/showproblem.php?pid=1348 造城墙问题,求出凸包加上一圈圆的周长即可 凸包模板题 #include <cstdio> #i ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
- hdu 1348(凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Surround the Trees(凸包求周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 4667 Building Fence(求凸包的周长)
A - Building Fence Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%I64d & %I64u ...
- (hdu step 7.1.7)Wall(求凸包的周长——求将全部点围起来的最小凸多边形的周长)
题目: Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
随机推荐
- FreeOnTerminate 的线程在线程管理类的Destroy释放时手工释放的问题
这个问题折腾了我整整一天. 有一个线程管理类,集中管理所有新建的线程, 线程统一在创建时标识 FreeOnTerminate 为 True. 因为有的线程是不限次循环的,所以在管理类最后 Destro ...
- Linux下资源利用率监测利器—nmon使用
最近接了一个任务,就是测试公司服务器的资源利用率,这样对每种业务平时所占资源有了大体的了解,进而为下一步的虚拟化做准备.找了很多开源的工具,但都不理想,有的安装很复杂,需要联网(而我们的服务器很多都不 ...
- bootstrap/moban191/js/templatemo_custom.js
(function($) { "use strict"; // Cache selectors var lastId, topMenu = $(".menu-holder ...
- ASP.NET数据验证控件的常用的属性
一.非空验证 RequiredFieldValidator ControlToValidate 所验证的控件ID Text 出错时的提示的文本 ErrorMessage 提交给Validati ...
- 文件输出debug
file_put_contents('/tmp/heat.log', var_export($mainArr, true),FILE_APPEND);
- hdwiki 数据库结构说明
HDWiki数据库结构说明 以下标有“A”的表示该列为自增列,标有“P”的表示该列为主码,标有“I”的表示该列为索引列,标有“U”的表示该列为唯一列,标有“F”的表示全文搜索. ...
- ACM题目————A simple problem
Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他. Input 第一行整数T,表示测试组 ...
- [转]application windows are expected to have a root view controller错误
转载地址:http://blog.sina.com.cn/s/blog_6784e6ea01017jfy.html 最新更正:这个提示几乎不影响编译和运行,可以不用设置. 产生这个提示的操作: ...
- Ajax案例:简易的购书网页
****使用Ajax可以不需要刷新整个页面,而使局部页面更新的技术: ****JSON是JavaScript得原生格式,JavaScript中处理JSON数据不需要特殊的工具或架包,其规则很简单,对象 ...
- 会话标识未更新(AppScan扫描结果)
最近工作要求解决下web的项目的漏洞问题,扫描漏洞是用的AppScan工具,其中此篇文章是关于会话标识未更新问题的.下面就把这块东西分享出来. 原创文章,转载请注明 ----------------- ...