HDU 3874
来源:互联网 发布:淘宝宝贝标题怎么优化 编辑:程序博客网 时间:2024/05/26 19:15
Allied Chute Manufacturers is a company that builds trash chutes. A trash chute is a hollow tube installed in buildings so that trash dropped in at the top will fall down and be collected in the basement. Designing trash chutes is actually highly nontrivial. Depending on what kind of trash people are expected to drop into them, the trash chute needs to have an appropriate size. And since the cost of manufacturing a trash chute is proportional to its size, the company always would like to build a chute that is as small as possible. Choosing the right size can be tough though.We will consider a 2-dimensional simplification of the chute design problem. A trash chute points straight down and has a constant width. Objects that will be dropped into the trash chute are modeled as polygons. Before an object is dropped into the chute it can be rotated so as to provide an optimal fit. Once dropped, it will travel on a straight path downwards and will not rotate in flight. The following figure shows how an object is first rotated so it fits into the trash chute.Your task is to compute the smallest chute width that will allow a given polygon to pass through. InputThe input contains several test cases. Each test case starts with a line containing an integer n (3 <= n <= 100), the number of points in the polygon that models the trash item.The next n lines then contain pairs of integers xi and yi (0 <= xi, yi <= 10^4), giving the coordinates of the polygon vertices in order. All points in one test case are guaranteed to be mutually distinct and the polygon sides will never intersect. (Technically, there is one inevitable exception of two neighboring sides sharing their common vertex. Of course, this is not considered an intersection.)The last test case is followed by a line containing a single zero.OutputFor each test case, display its case number followed by the width of the smallest trash chute through which it can be dropped. Display the minimum width with exactly two digits to the right of the decimal point, rounding up to the nearest multiple of 1/100. Answers within 1/100 of the correct rounded answer will be accepted.Sample Input30 03 00 440 1010 020 1010 200Sample OutputCase 1: 2.40Case 2: 14.15
一个关于凸包的题,一开始标记的那段代码中,i和j反了,wa了好久,
#include<iostream>#include<cstring>#include<string>#include<cmath>#include<cstdio>#include<algorithm>#include<set>#include<fstream>using namespace std;#define maxn 10000#define inf 0x3f3f3f3f#define eps 1e-8int dcmp ( double x ){ return ( x > eps ) - ( x < eps );}struct point { double x,y; point(){}; point ( double xx,double yy ){ x = xx, y = yy; } bool operator < ( const point&b ) const { return x == b.x ? y < b.y : x < b.x; } double len (){ return sqrt(y*y + x*x); } point operator + ( const point&b ) const { return point(x+b.x, y + b.y); } point operator - ( const point&b) const { return point( x-b.x, y - b.y); }}res[maxn],pnt[maxn];double cross ( point a,point b){ return a.x*b.y - a.y*b.x;}double dis ( point a, point b){ return (a-b).len();}double ptoline ( point x, point a, point b){ return fabs(cross(x-a,b-a)) /dis(a,b);}int andrew( point *a ,int n){ sort(a,a+n); int cnt = 0; for( int i = 0; i < n ;i ++ ){ while( cnt > 1 && dcmp( cross(res[cnt-1]-res[cnt-2],a[i]-res[cnt-2]) ) < 0 ) cnt--; res[cnt++] = a[i]; } int k = cnt; for( int i = n-1; i >= 0; i-- ){ while( cnt > k && dcmp( cross(res[cnt-1]-res[cnt-2],a[i]-res[cnt-2]) ) < 0 ) cnt --; res[cnt++] = a[i]; } if( cnt > 1 ) cnt --; return cnt;}int main(){ int n,t = 1;; while( ~scanf("%d",&n) && n ){ for( int i = 0; i < n; i++ ) scanf("%lf%lf",&pnt[i].x,&pnt[i].y); int cnt = andrew(pnt,n); res[cnt] = res[0]; double ans = inf*1.0,temp ; for( int i = 0; i < cnt ; i++ ){ temp = 0.0; for( int j = 0; j < cnt; j++ ) temp = max ( temp, ptoline(res[j],res[i],res[i+1] ) ); ans = min ( ans, temp ); } printf("Case %d: %.2lf\n",t++,ans+0.005); } return 0;}
0 0
- HDU 3874
- hdu 3874
- hdu 3874
- hdu 3874 树状数组
- hdu 3874(树状数组)
- hdu 3874 Necklace
- hdu 3874 Necklace
- hdu 3874 Necklace
- hdu 3874 Necklace
- hdu 3874 树状数组
- HDU 3874 树状数组
- hdu 3874 树状数组
- HDU 3874 Necklace
- HDU 3874__Necklace
- HDU 3874 Necklace
- hdu
- hdu
- HDU
- PHP系统学习(1)
- prototype.js 1.4版开发者手册(强烈推荐)
- HttpServletRequest
- http status汇总
- linux多线程实现黑客帝国字符滑屏效果
- HDU 3874
- fatal error C1083: Cannot open include file: 'qwtplot.h':
- 荷兰国旗问题
- lucene入门01
- ubuntu 更换最新的163源
- 非线性,加权,放大和缩小,卷积
- C语言100个经典的算法
- quick-cocos2d-x 如何设置游戏的屏幕方向
- 背包问题