uva 10065 (凸包+求面积)
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=1006
Problem A
Useless Tile Packers
Input: standard input
Output: standard output
Yes, as you have apprehended the Useless Tile Packers (UTP) pack tiles. The tiles are of uniform thickness and have simple polygonal shape. For each tile a container is custom-built. The floor of the container is a convex polygon and under this constraint it has the minimum possible space inside to hold the tile it is built for. But this strategy leads to wasted space inside the container.
The UTP authorities are interested to know the percentage of wasted space for a given tile.
Input
The input file consists of several data blocks. Each data block describes one tile.
The first line of a data block contains an integer N (3 <= N <= 100) indicating the number of corner points of the tile. Each of the next N lines contains two integers giving the (x, y) co-ordinates of a corner point (determined using a suitable origin and orientation of the axes) where 0 <= x, , y <= 1000. Starting from the first point given in the input the corner points occur in the same order on the boundary of the tile as they appear in the input. No three consecutive points are co-linear.
The input file terminates with a value of 0 for N.
Output
For each tile in the input output the percentage of wasted space rounded to two digits after the decimal point. Each output must be on a separate line. Print a blank line after each output block.
Sample Input
5
0 0
2 0
2 2
1 1
0 2
5
0 0
0 2
1 3
2 2
2 0
0
Sample Output
Tile #1
Wasted Space = 25.00 %
Tile #2
Wasted Space = 0.00 %
________________________________________________________________________________
Rezaul Alam Chowdhury
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
让求空闲的面积,简单转化一下,就是求建造凸包之前的面积,以及建造凸包之后的面积,相减,再相除即可
犯了个好傻的毛病,把求叉乘积的函数,以及距离的函数类型定义为bool,搞的一直出不来结果,最后调试两遍才发现,汗!!!
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm> using namespace std;
#define MAXX 105
#define eps 1e-8 typedef struct point
{
double x;
double y;
}point; bool xy(double x,double y){ return x<y-eps; }
bool dy(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));
} point p[MAXX];
point stk[MAXX];
int top; bool cmp(point a,point b)
{
double len=crossProduct(p[],a,b);
if(dd(len,0.0))
{
return xy(dist(p[],a),dist(p[],b));
}
return xy(len,0.0);
} void Graham(int n)
{
int tmp=;
for(int i=; i<n; i++)
{
if(xy(p[i].x,p[tmp].x) || dd(p[i].x,p[tmp].x) && xy(p[i].y,p[tmp].y))
{
tmp=i;
}
}
swap(p[],p[tmp]);
sort(p+,p+n, cmp); stk[]=p[];
stk[]=p[];
top=;
for(int i=; i<n; i++)
{
while(top && xyd(crossProduct(stk[top],stk[top-],p[i]),0.0))
top--;
stk[++top]=p[i];
}
} double Area(int n,point ss[])
{
double ans=0.0;
for(int i=; i<n; i++)
{
ans+=crossProduct(ss[],ss[i-],ss[i]);//printf("%lf^^\n",ans);
}
return fabs(ans)/2.0;
} int main()
{
int n,m,i,j;
int cas=;
while(scanf("%d",&n)!=EOF &&n)
{
for(i=; i<n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
double ans_min=Area(n,p);
Graham(n);//printf("%d--",top);
double ans_max=Area(top+,stk);
printf("Tile #%d\n",cas++);
printf("Wasted Space = %.2lf %%\n\n",(ans_max-ans_min)/ans_max*);
}
return ;
}
第一道uva的题,做个纪念、uva 的邮件
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
This is an automated response from UVa Online Judge.
Your submission with number 14050702 for the problem 10065 - Useless Tile Packers has succeeded with verdict Accepted.
The UVa Online Judge team
uva 10065 (凸包+求面积)的更多相关文章
- poj 3348--Cows(凸包求面积)
链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: ...
- Cows - POJ 3348(凸包求面积)
题目大意:利用n棵树当木桩修建牛圈,知道每头牛需要50平的生存空间,求最多能放养多少头牛. 分析:赤裸裸的求凸包然后计算凸包的面积. 代码如下: --------------------------- ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- POJ-3348 Cows 计算几何 求凸包 求多边形面积
题目链接:https://cn.vjudge.net/problem/POJ-3348 题意 啊模版题啊 求凸包的面积,除50即可 思路 求凸包的面积,除50即可 提交过程 AC 代码 #includ ...
- 简单几何(凸包+多边形面积) POJ 3348 Cows
题目传送门 题意:求凸包 + (int)求面积 / 50 /************************************************ * Author :Running_Tim ...
- POJ 3348 Cows(凸包+多边形面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
- POJ 3348 /// 凸包+多边形面积
题目大意: 给定的n个点 能圈出的最大范围中 若每50平方米放一头牛 一共能放多少头 求凸包 答案就是 凸包的面积/50 向下取整 /// 求多边形面积// 凹多边形同样适用 因为点积求出的是有向面积 ...
- zoj 1453 Surround the Trees(凸包求周长)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds Memory ...
随机推荐
- JS 字符串转日期格式 日期格式化字符串
/** * @author 陈维斌 http://www.cnblogs.com/Orange-C/p/4042242.html%20 3 * 如果想将日期字符串格式化,需先将其转换为日期类型Date ...
- 【python cookbook】【数据结构与算法】10.从序列中移除重复项且保持元素间顺序不变
问题:从序列中移除重复的元素,但仍然保持剩下的元素顺序不变 解决方案: 1.如果序列中的值时可哈希(hashable)的,可以通过使用集合和生成器解决.
- zjtd 2016面试
1.写一个函数get_next() class A{ public :int next(); //取下一个值,并且指针后移 bool has_next(); private: //可以认为是一个q ...
- new和malloc的区别
1.malloc与free是C++/C语言的标准库函数,new/delete是C++的运算符 2.new出来的指针是直接带类型信息的,而malloc返回的都是void*指针. 3.new 建立的是一个 ...
- js对select动态添加和删除OPTION
<select id="ddlResourceType" onchange="getvalue(this)"> </select> 动态 ...
- Oracle:Authid Current_User使用
由于用户拥有的role权限在存储过程是不可用的.遇到这种情况,我们一般需要显示授权,如grant create table to user;但这种方法太麻烦,有时候可能需要进行非常多的授权才能执行存储 ...
- ectouch第十讲 之ecshop中 dwt, lbi 文件详解
原文:http://www.yunmoban.cn/article-241.html Ecshop包括的文件夹有admin.api.cert.data.images.includes.js. lang ...
- C++11 std::function用法
转自 http://www.hankcs.com/program/cpp/c11-std-function-usage.html function可以将普通函数,lambda表达式和函数对象类统一起来 ...
- js词法作用域规则
function foo() {console.log( a ); // 2不是3} function bar() {var a = 3;foo();} var a = 2;bar(); js中的作用 ...
- 20145227 《Java程序设计》第7周学习总结
20145227 <Java程序设计>第7周学习总结 教材学习内容总结 第十二章 Lambda 如果使用JDK8的话,可以使用Lambda特性去除重复的信息. 在只有Lambda表达式的情 ...