链接: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 (xy) 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 的邮件

××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××

Hi,

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.

Congratulations! Now it is time to try a new problem.

Best regards,

The UVa Online Judge team

×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××

uva 10065 (凸包+求面积)的更多相关文章

  1. poj 3348--Cows(凸包求面积)

    链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:  ...

  2. Cows - POJ 3348(凸包求面积)

    题目大意:利用n棵树当木桩修建牛圈,知道每头牛需要50平的生存空间,求最多能放养多少头牛. 分析:赤裸裸的求凸包然后计算凸包的面积. 代码如下: --------------------------- ...

  3. POJ 3348 Cows 凸包 求面积

    LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...

  4. poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7038   Accepted: 3242 Description ...

  5. POJ-3348 Cows 计算几何 求凸包 求多边形面积

    题目链接:https://cn.vjudge.net/problem/POJ-3348 题意 啊模版题啊 求凸包的面积,除50即可 思路 求凸包的面积,除50即可 提交过程 AC 代码 #includ ...

  6. 简单几何(凸包+多边形面积) POJ 3348 Cows

    题目传送门 题意:求凸包 + (int)求面积 / 50 /************************************************ * Author :Running_Tim ...

  7. POJ 3348 Cows(凸包+多边形面积)

    Description Your friend to the south is interested in building fences and turning plowshares into sw ...

  8. POJ 3348 /// 凸包+多边形面积

    题目大意: 给定的n个点 能圈出的最大范围中 若每50平方米放一头牛 一共能放多少头 求凸包 答案就是 凸包的面积/50 向下取整 /// 求多边形面积// 凹多边形同样适用 因为点积求出的是有向面积 ...

  9. zoj 1453 Surround the Trees(凸包求周长)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds      Memory ...

随机推荐

  1. tmpfs

    什么是tmpfs tmpfs是Linux/Unix系统上的一种基于内存的文件系统.tmpfs可以使用您的内存或swap分区来存储文件.由此可见,temfs主要存储暂存的文件. linux内核中的VM子 ...

  2. vsftp黑白名单设置及问题

    问题一:ftpusers和user_list两个文件各自的用途是什么?有何关系? 首先请明确一点:ftpusers不受任何配制项的影响,它总是有效,它是一个黑名单!该文件存放的是一个禁止访问FTP的用 ...

  3. 160921、React入门教程第一课--从零开始构建项目

    工欲善其事必先利其器,现在的node环境下,有太多好用的工具能够帮助我们更好的开发和维护管理项目. 我本人不建议什么功能都自己写,我比较喜欢代码复用.只要能找到npm包来实现的功能,坚决不自己敲代码. ...

  4. Mysql密码恢复

    由于种种原因,Mysql root用户的密码可能被恶意篡改,这个时候就需要对Mysql进行密码恢复了.大致步骤如下: 1.修改MySQL的登录设置: # vi /etc/my.cnf 在[mysqld ...

  5. PHP序列化以及反序列化系列[1]--PHP序列化格式的写法

    反序列化:对单一的已序列化的变量进行操作,将其转换回 PHP 的值(zval). PHP序列化方式 PHP在序列化的时候会将相应的变量以对应的键值进行储存. 将一个类序列化的话,处理代码主要的 文件: ...

  6. Python使用报错记录

    问题1:pip 报错 C:\Users\Administrator>pip3 install pyreadline Fatal error in launcher: Unable to crea ...

  7. POJ 1260:Pearls(DP)

    http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8 ...

  8. StringUtils中 isEmpty 和isBlank的区别

    StringUtils方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出Nu ...

  9. php 计算两个日期之间的差,得出:年月日时分秒

    <?php$time1 = "2008-6-15 11:49:59";//第一个时间$time2 = "2007-5-5 12:53:28";//第二个时 ...

  10. Power Network 分类: POJ 2015-07-29 13:55 3人阅读 评论(0) 收藏

    Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24867 Accepted: 12958 Descr ...