UVA10652凸包简单应用
来源:互联网 发布:mac怎么打开rar压缩包 编辑:程序博客网 时间:2024/05/07 20:15
这题本身并没什么难度,就是一个裸的凸包,只是有一点我没想到而已,
就是如何根据矩形中点坐标求出矩形顶点的坐标,它这里是使用平移的思想,
假设凸包中点在圆心,然后根据从中心出发的向量加上中心坐标来求得顶点坐标。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<cctype>
#define LL long long
using namespace std;
const double eps=1e-10;
const double pi=acos(-1.0);
int dcmp(double x)
{
if(fabs(x)<eps)
return 0;
return x>0?1:-1;
}
struct point
{
double x,y;
point() {}
point(double x,double y):x(x),y(y){}
point operator + (const point &t) const
{
return point(x+t.x,y+t.y);
}
point operator - (const point &t) const
{
return point(x-t.x,y-t.y);
}
bool operator < (const point &t) const
{
return x+eps<t.x||(!dcmp(x-t.x)&&y<t.y);
}
bool operator == (const point &t)
{
return dcmp(x-t.x)&&dcmp(y-t.y)==0;
}
};
point rotate(point a,double rad)
{
return point(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
double dot(point a,point b)
{
return a.x*b.x+a.y*b.y;
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
double area(point *p,int n)
{
double area=0;
for(int i=1;i<n-1;i++)
area+=cross(p[i]-p[0],p[i+1]-p[0]);
return area/2;
}
double torad(double deg)
{
return deg/180*acos(-1);
}
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;
}
int main()
{
int t;
cin>>t;
point p[2500],ch[2500];
while(t--)
{
int n,pc=0;
double area1=0;
cin>>n;
for(int i=0;i<n;i++)
{
double x,y,w,h,j,ang;
cin>>x>>y>>w>>h>>j;
ang=-torad(j);
point o(x,y);
p[pc++]=o+rotate(point(-w/2,-h/2),ang);
p[pc++]=o+rotate(point(w/2,-h/2),ang);
p[pc++]=o+rotate(point(-w/2,h/2),ang);
p[pc++]=o+rotate(point(w/2,h/2),ang);
area1+=w*h;
}
int m=ConvexHull(p,pc,ch);
double area2=area(ch,m);
printf("%.1f %%\n",area1*100/area2);
}
return 0;
}
- UVA10652凸包简单应用
- UVA10652【凸包计算】
- uva10652 Board Wrapping(凸包)
- uva10652 Board Wrapping(凸包)
- 凸包 模板【uva10652】Board Wrapping
- UVa10652
- UVa10652
- poi包简单应用
- js闭包简单应用
- hdu 2018 简单的凸包思想应用
- linux 抓包 tcpdump 简单应用
- 关于Swing 包的一个简单应用
- uva10652 Board Wrapping
- 凸包及其应用
- 凸包应用
- 简单凸包
- 例题4.6 包装木板 UVa10652
- Microsoft TTS(Text To Speech)语音包的简单应用
- ubuntu[14.10] chromium 浏览器安装flashplayer[flash]及下载
- codeforces 438D
- 为动态加载的PartialView传递一个参数
- 编写一个函数reverse_string(char * string) 实现:将参数字符串中的字符反向排列。
- 构造函数,析构函数和虚函数相关问题
- UVA10652凸包简单应用
- 一个ThreadLocal实例
- IO标准库
- [leetcode]27 Reverse Bits
- 【总结】专业相关不错的一些话
- 重拾Android之ActionBar的简单使用
- win32绘图
- Android开发_标题栏布局设置
- 用户安全