10065 - Useless Tile Packers

Problem A

Useless Tile Packers

Input: standard input

Output: standard output

 

Yes, as you have apprehended the Useless Tile Packers (UTP) pack tiles. Thetiles are of uniform thickness and have simple polygonal shape. For each tile acontainer is custom-built. The floor of the container is a convex polygon and underthis constraint it has the minimum possible space inside to hold the tile it isbuilt for. But this strategy leads to wasted space inside the container.

 

                            

 

The UTPauthorities are interested to know the percentage of wasted space for a giventile.

 

Input

The input file consists ofseveral data blocks. Each data block describes one tile.

The first lineof a data block contains an integer N (3 <= N <= 100) indicating the number of corner points of the tile. Each of the nextN lines contains two integers giving the(x, y) co-ordinates of a corner point (determined using a suitable originand orientation of the axes) where 0 <= x, ,y <= 1000. Starting from the first point given in the input the corner points occurin the same order on the boundary of the tile as they appear in the input. Nothree consecutive points are co-linear.

The input fileterminates with a value of 0 for N.

 

Output

For each tile in the input outputthe 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 %
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
struct point
{double x;double y;
point(double x=0, double y=0):x(x),y(y){}
}p[100005],a,ch[100005];

typedef point vector;

vector operator-(point a,  point b){return vector(a.x-b.x,a.y-b.y);}
double cross(vector a, vector b){return a.x*b.y-a.y*b.x;}
bool operator<(const point& a,const point& b)  
{  
	return a.x<b.x||(a.x==b.x&&a.y<b.y);  
}  

int convexhull(point *p,int n,point *ch)
{
	sort(p,p+n);
	int m=0;
	for(int i=0;i<n;i++)
	{
		while(m>1&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
			m--;
		ch[m++]=p[i];
	}
	int k=m;
	for(int i=n-2;i>=0;i--)
	{
		while(m>k&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)	
			m--;
		ch[m++]=p[i];
	}
	if(n>1) m--;
	return m;
}
double area(point *p, int N)  
{  
	double total=0.0;  
	for (int i=0;i<N; i++)  
	{  
		int j=(i+1)%N;  
		total+=(p[i].x*p[j].y-p[j].x*p[i].y);  
	}  
	return fabs(total/2.0);  
}  
int main()
{
	int n,t,count=1;
	while(cin>>n)
	{
		if(!n) break;
		for(int i=0;i<n;i++)
			cin>>p[i].x>>p[i].y;
		double a1=area(p,n);
		int m=convexhull(p,n,ch);
		double a2=area(ch,m);
		cout<<"Tile #"<<count++<<endl<<"Wasted Space = ";
		printf("%.2f %%\n\n",(a2-a1)/a2*100);
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值