[Swust OJ 249]--凸包面积
现在,给出了这些墨点的坐标,请帮助麦兜计算出覆盖这些墨点的最小凸多边形的面积。
每组测试数据的第一行是一个正整数N(0< N < = 105),表明了墨点的数量。接下来的N行每行包含了两个整数Xi和Yi(0<=Xi,Yi<=2000),表示每个墨点的坐标。每行的坐标间可能包含多个空格。
|
1
2
3
4
5
6
7
8
9
|
2
4
0 0
1 0
0 1
1 1
2
0 0
0 1
|
|
1
2
|
1.0
0.0
|
area += (pos.x*tmp.y - pos.y*tmp.x) / 2.0;(pos当前点,tmp下一个点,最后一个点和第一个点在来一次)#include<iostream>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<cmath>
using namespace std;
struct node{
double x, y;
}point[], pos, tmp;
double dis(node a, node b){
return pow((a.x - b.y), ) + pow((a.y - b.y), );
}
//按点集分布排序,利用向量平行关系判断(极角排序),角度相同则距离小的在前面
bool cmp(node a, node b){
double povit = (a.x - pos.x)*(b.y - pos.y) - (b.x - pos.x)*(a.y - pos.y);
if (povit > || !povit && (dis(a, pos) < dis(b, pos)))
return true;
return false;
}
//当前点是否在点集左侧,利用叉乘比较3个点两条线的斜率关系
bool turn_left(node p1, node p2, node p3){
return (p2.x*p1.y + p3.x*p2.y + p1.x*p3.y - p3.x*p1.y - p1.x*p2.y - p2.x*p3.y) > ? true : false;
}
int main(){
int i, sign, n, t;
double area;
cin >> t;
while (t--){
cin >> n;
for (i = ; i < n; i++)
cin >> point[i].x >> point[i].y;
if (n <= ){
cout << "0.0\n";
continue;
}
stack<node> Q;
sign = ;
pos = point[];
for (i = ; i < n; i++){
if (pos.y == point[i].y&&pos.x>point[i].x || point[i].y < pos.y){
pos = point[i];
sign = i;
}
}
swap(point[], point[sign]);
sort(point + , point + n, cmp);
Q.push(point[]), Q.push(point[]), Q.push(point[]);
for (i = ; i < n; i++){
while (!Q.empty()){
tmp = Q.top();
Q.pop();
if (turn_left(tmp, Q.top(), point[i])){
Q.push(tmp);
break;
}
}
Q.push(point[i]);
}
area = ;
tmp = Q.top(), Q.pop();
area += (pos.x*tmp.y - pos.y*tmp.x) / 2.0;
while (!Q.empty()){
area += (tmp.x*Q.top().y - tmp.y*Q.top().x) / 2.0;
tmp = Q.top();
Q.pop();
}
printf("%.1lf\n", fabs(area));
}
return ;
}
主要的地方就是利用向量平行关系,按点集的离散化排序
(没说清楚~~~看凸包的简单概念吧http://www.cnblogs.com/zyxStar/p/4540984.html),
判断下一个的点能否覆盖已选取的点~~
[Swust OJ 249]--凸包面积的更多相关文章
- [Swust OJ 567]--老虎在不在笼子里(凸包问题)
题目链接:http://acm.swust.edu.cn/problem/567/ Time limit(ms): 1000 Memory limit(kb): 65535 一只老虎自从看了< ...
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- [Swust OJ 404]--最小代价树(动态规划)
题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Des ...
- [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)
题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...
- poj 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
- poj 3348:Cows(计算几何,求凸包面积)
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6199 Accepted: 2822 Description ...
- uva109求凸包面积,判断点是不是在凸包内
自己想了一个方法判断点是不是在凸包内,先求出凸包面积,在求由点与凸包上每两个点之间的面积(点已经排好序了),如果两者相等,则点在凸包内,否则不在(时间复杂度可能有点高)但是这题能过 #include& ...
- poj3348凸包面积
用叉积求凸包面积 如图所示,每次找p[0]来计算,(叉积是以两个向量构成的平行四边形的面积,所以要/2) #include<map> #include<set> #includ ...
- poj 3348(凸包面积)
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8063 Accepted: 3651 Description ...
随机推荐
- Lucence.Net+添加关键词+分页+排序
1.使用queryparser完成解析搜索请求 2.基本格式如: QueryParser parser=new QueryParser("字段名称","分析器实例&quo ...
- centos6.5 升级python 到 python 2.7.11 安装 pip
1.首先官方下载源码,然后安装(./configure,make all,make install,make clean,make distclean) 注意:需要先安装zlib-devel,open ...
- Hadoop MultipleOutputs 结果输出到多个文件夹 出现数据不全,部分文件为空
如题:出现下图中的情况(设置reduceNum=5) 感觉很奇怪,排除了很久,终于发现是一个第二次犯的错误:丢了这句 this.mOutputs.close(); 加上这句,一切恢复正常!
- 手动添加删除windows服务
1.使用sc命令创建服务 命令格式如: sc create [service name] [binPath= ] <option1> <option2>... 比如: sc c ...
- 细说SSO单点登录(转)
什么是SSO? 如果你已知道,请略过本节! SSO核心意义就一句话:一处登录,处处登录:一处注销,处处注销.即:在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统. 很多人容易把SS ...
- Php 使用 fsockopen发送http请求
<?php function HTTP_Post($URL,$data, $referrer="") { // parsing the given URL $URL_Info ...
- How to setup linked servers for SQL Server and Oracle 64 bit client
感谢作者:Tim Ford. 图文并茂. 原帖地址: http://www.mssqltips.com/sqlservertip/1433/how-to-setup-linked-servers-fo ...
- [置顶] Android资源文件分析
1)修改开机默认壁纸 Android开机默认资源文件为:frameworks/base/core/res/res/values/config.xml 我们找到wallpaper行: <strin ...
- Silverlight CheckBoxList
项目要用到复选框,可是在Silverlight中不存在CheckBoxList.通过查阅资料以及依据自己的理解,写了简单演示样例: 1.XAML <UserControl x:Class=&qu ...
- [译]Stairway to Integration Services Level 15 – SSIS 参数回顾
介绍 在本文中我们会研究SSIS变量姐妹: SSIS 变量. 我们会演示参数配置,通过包参数管理动态属性值,然后会演示SSIS包执行的时候参数怎么被配置的. SSIS Parameters 101 S ...