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 ...
随机推荐
- java简单的数据库查询(SQLServer数据库)
1.数据库链接类 import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; pu ...
- Web SQL
HTML5本地存储——Web SQL Database 基于 HTML5 中的 Web SQL Database 来构建应用程序 前端HTML5几种存储方式的总结 <!DOCTYPE HTML& ...
- centos7重启rsyslog服务|centos7重启syslog服务
centos7重启rsyslog服务: systemctl restart rsyslog 使用:(killall无效) killall -HUP rsyslog
- org.hibernate.TransientObjectException
使用JPA注解@ManyToMany做一个多对多的用例. 为了避免在删除主表数据时同时级联删除从表数据,JPA官方文档建议在主表的从表字段使用级联注解:CascadeType.PERSIST,Casc ...
- php获取目录中的所有文件名
<?php /** * [php获取目录中的所有文件名] */ //1.先打开要操作的目录,并用一个变量指向它 //打开当前目录下的目录pic下的子目录common. $handler = op ...
- 在chrome浏览器和在IE浏览器中显示的页面样式不一样的解决办法
在IE浏览器中添加 一行代码即可:<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 位 ...
- DevExpress.XtraGrid.Views.BandedGrid.BandedGridView
使用的是DevExpress.XtraGrid.Views.BandedGrid.BandedGridView 类 没有在工具箱里找到对应控件 ,绕了一下,先创建一个gridcontrol ,然后gr ...
- c#之线程池
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- c#之双色球
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- OracleHelper 动软生成
using System; using System.Collections; using System.Collections.Specialized; using System.Data; usi ...