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 ...
随机推荐
- Android的适配器
//====================ArrayAdapter=================================== public class List1 extends Ac ...
- android 应用架构随笔二(定义BaseApplication并配置Application)
定义BaseApplication并配置Application import android.app.Application; import android.os.Handler; /** * * = ...
- button改变背景与文字颜色
1.定义/zhsh/res/color/txt_guide_selector.xml <?xml version="1.0" encoding="utf-8&quo ...
- Java中IO流中所涉及到的各类方法介绍
IO流之字节流 (1)IO用于在设备间进行数据传输的操作 (2)分类: A:流向 输入流 读取数据 输出流 写出数据 B:数据类型 字节流 字节输入流 字节输出流 字符流 字符输入流 字符输出流 注意 ...
- iOS 序列化与反序列化
开篇 1到底这个序列化有啥作用? 面向对象的程序在运行的时候会创建一个复杂的对象图,经常要以二进制的方法序列化这个对象图,这个过程叫做Archiving. 二进制流可以通过网络或写入文件中(来源于某教 ...
- 不定参数的传递VA_LIST的用法
VA_LIST的用法:(1)首先在函数里定义一具VA_LIST型的变量,这个变量是指向参数的指针: (2)然后用VA_START宏初始化变量刚定义的VA_LIST变量,使其指向第一个可 变参数的地址: ...
- PRINCE2七大原则(2)
PRINCE2七大原则(2) 我们先来回顾一下,PRINCE2七大原则分别是持续的业务验证,经验学习,角色与责任,按阶段管理,例外管理,关注产品,剪裁. 第二个原则:吸取经验教训. PRINCE2要求 ...
- 第十一章 Android 内核驱动——Alarm
11.1 基本原理 Alarm 闹钟是 android 系统中在标准 RTC 驱动上开发的一个新的驱动,提供了一个定时器 用于把设备从睡眠状态唤醒,当然因为它是依赖 RTC 驱动的,所以它同时还可以 ...
- I Think I Need a Houseboat 分类: POJ 2015-06-11 17:52 12人阅读 评论(0) 收藏
I Think I Need a Houseboat Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 92090 Acce ...
- UVa 10054,欧拉回路
题目链接:https://uva.onlinejudge.org/external/100/10054.pdf 题目链接:http://vjudge.net/contest/132239#proble ...