POJ 3246 Game(凸包)
【题目链接】 http://poj.org/problem?id=3246
【题目大意】
给出一些点,请删去一个点,使得包围这些点用的线长最短
【题解】
去掉的点肯定是凸包上的点,所以枚举凸包上的点去掉,再计算面积即可。
【代码】
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
using namespace std;
struct P{
int x,y;
int id;
P(){}
P(double x,double y):x(x),y(y){}
P operator + (P p){return P(x+p.x,y+p.y);}
P operator - (P p){return P(x-p.x,y-p.y);}
P operator * (double d){return P(x*d,y*d);}
int dot(P p){return x*p.x+y*p.y;} //点积
int det(P p){return x*p.y-y*p.x;} //叉积
};
bool cmp_x(const P& p,const P& q){
if(p.x!=q.x)return p.x<q.x;
return p.y<q.y;
}
vector<P> convex_hull(P* ps,int n){
sort(ps,ps+n,cmp_x);
int k=0;
vector<P> qs(n*2);
for(int i=0;i<n;i++){
while((k>1)&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)k--;
qs[k++]=ps[i];
}
for(int i=n-2,t=k;i>=0;i--){
while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)k--;
qs[k++]=ps[i];
}qs.resize(k-1);
return qs;
}
int cross(P a, P b,P c){return(b-a).det(c-a);}
int compute_area(P A,P B,P C){
int res=cross(A,B,C);
if(res<0){return -res;}
return res;
}
int compute_area(const vector<P>& ps){
int total=0;
for(int i=2;i<ps.size();i++){
total+=compute_area(ps[0],ps[i-1],ps[i]);
}return total;
}
const int MAX_N=100010;
int N;
P p[MAX_N],q[MAX_N];
void solve(){
for(int i=0;i<N;i++){
scanf("%d%d",&p[i].x,&p[i].y);
p[i].id=i;
}memcpy(q,p,N*sizeof(P));
vector<P> ps=convex_hull(p,N);
int ans=0x3f3f3f3f;
for(int i=0;i<ps.size();i++){
memcpy(p,q,N*sizeof(P));
swap(p[ps[i].id],p[N-1]);
ans=min(ans,compute_area(convex_hull(p,N-1)));
}printf("%d.%s\n",ans/2,ans%2==1?"50":"00");
}
int main(){
while(~scanf("%d",&N),N)solve();
return 0;
}
POJ 3246 Game(凸包)的更多相关文章
- poj 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
- poj 1228 稳定凸包
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12337 Accepted: 3451 ...
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- POJ 1113 Wall 凸包 裸
LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...
- poj 1113 Wall 凸包的应用
题目链接:poj 1113 单调链凸包小结 题解:本题用到的依然是凸包来求,最短的周长,只是多加了一个圆的长度而已,套用模板,就能搞定: AC代码: #include<iostream> ...
- POJ 1113 - Wall 凸包
此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包. 初次提交被坑得很惨,在GDB ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
随机推荐
- PHP 5.4语法改进与弃用特性
PHP 5.4于本月尘埃落定,它是 PHP 自 2009 年以来的首次重大更新.该版本对语言部分进行了增强,包括支持 Traits 和移除部分争议特性. Traits 同 Java 和 .NET 一样 ...
- C语言指针大杂烩
By francis_hao Oct 31,2016 指针数组和数组指针 指针数组本身是个数组,数组的内容是指针.形如char *pa[].由于[]优先级高于*,pa先于[]结合表示pa是一个数组,p ...
- HDU 多校对抗赛 D Distinct Values
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 数据结构之(HDU2051 Bitset)
Problem Description Give you a number on base ten,you should output it on base two.(0 < n < 10 ...
- Spring - IoC(9): @Resoure & @Autowired
@Resource 和 @Autowired 都是用来装配依赖的,它们之间有些异同. @Resoure @Resource 是 JSR-250 规范的注解. @Resource 可以标注在字段.方法上 ...
- [转载]解决clickonce不支持administer权限问题
转自ClickOnce deployment vs. requestedExecutionLevel = requireAdministrator ClickOnce方式部署应用简单方便,估计很多人都 ...
- Node.js 编码转换
Node.js自带的toString()方法不支持gbk,因此中文转换的时候需要加载第三方库,推荐以下两个编码转换库,iconv-lite和encoding. iconv, iconv-l ...
- 服务器应用程序不可用,由于无法创建应用程序域,因此未能执行请求。错误: 0x80070002 系统找不到指定的文件。
使用360更新网站补丁导致.net2.0环境报错问题现象:服务器应用程序不可用查看日志:出现由于无法创建应用程序域,因此未能执行请求.错误: 0x80070002 系统找不到指定的文件. 搜索定位:罪 ...
- CentOS 7 主机加固手册-上
TIPs: 世界上有一撮人专门研究主机安全加固基线,有兴趣的读者可以到 http://benchmarks.cisecurity.org/ 获取更加详细专业的主机安全基线配置文档.或者到 https: ...
- 设置session过期时间
1如下是登录注册和记住密码的功能: # -*- coding: utf-8 -*- def cms_login(request): if request.method == 'GET': return ...