poj1873(二进制枚举+求凸包周长)
题目链接:https://vjudge.net/problem/POJ-1873
题意:n个点(2<=n<=15),给出n个点的坐标(x,y)、价值v、做篱笆时的长度l,求选择哪些点来做篱笆围住另一些点,使得选出的这些点的价值和最小,如果价值和相等要求个数最小。
思路:
看来这是WF的签到题吧。数据很小,直接二进制枚举 (1<<n),然后对未选出的点求凸包的周长,仅当选出点的长度l的和>=凸包周长时才更新答案。
AC code:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; const int maxn=;
const int inf=0x3f3f3f3f; struct Point{
int x,y;
Point():x(),y(){}
Point(int x,int y):x(x),y(y){}
}; int n,cas,val,num,res[maxn],v[maxn],l[maxn],vis[maxn];
double ext;
int top,stack[maxn];
Point pt[maxn],list[maxn]; int cross(Point p0,Point p1,Point p2){
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} double dis(Point p1,Point p2){
return sqrt((double)(p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
} bool cmp(Point p1,Point p2){
int tmp=cross(list[],p1,p2);
if(tmp>) return true;
else if(tmp==&&dis(list[],p1)<dis(list[],p2)) return true;
else return false;
} void init(int m){
Point p0=list[];
int k=;
for(int i=;i<m;++i){
if((p0.y>list[i].y)||((p0.y==list[i].y)&&(p0.x>list[i].x))){
p0=list[i];
k=i;
}
}
list[k]=list[];
list[]=p0;
sort(list+,list+m,cmp);
} double graham(int m){
if(m==){
top=;
stack[]=;
}
else{
top=;
stack[]=;
stack[]=;
for(int i=;i<m;++i){
while(top>&&cross(list[stack[top-]],list[stack[top]],list[i])<=) --top;
stack[++top]=i;
}
}
double ret=;
for(int i=;i<top;++i)
ret+=dis(list[stack[i]],list[stack[i+]]);
ret+=dis(list[stack[top]],list[stack[]]);
return ret;
} int main(){
while(scanf("%d",&n),n){
val=num=inf;
for(int i=;i<n;++i)
scanf("%d%d%d%d",&pt[i].x,&pt[i].y,&v[i],&l[i]);
for(int i=;i<(<<n)-;++i){
int t1=,t2=,cnt=;
for(int j=;j<n;++j){
if((i>>j)&){
t1+=v[j],t2+=l[j];
}
else{
list[cnt++]=pt[j];
}
}
init(cnt);
int cnt2=n-cnt;
if((t1<val)||((t1==val)&&(cnt2<num))){
double tmp=graham(cnt);
if(tmp>t2) continue;
val=t1,num=cnt2,ext=t2-tmp;
int t=;
for(int j=;j<n;++j){
if((i>>j)&)
res[t++]=j;
}
}
}
printf("Forest %d\nCut these trees:",++cas);
for(int i=;i<num;++i)
printf(" %d",res[i]+);
printf("\nExtra wood: %.2f\n\n",ext);
}
return ;
}
poj1873(二进制枚举+求凸包周长)的更多相关文章
- The Fortified Forest - POJ 1873(状态枚举+求凸包周长)
题目大意:有个国王他有一片森林,现在他想从这个森林里面砍伐一些树木做成篱笆把剩下的树木围起来,已知每个树都有不同的价值还有高度,求出来砍掉那些树可以做成篱笆把剩余的树都围起来,要使砍伐的树木的价值最小 ...
- HDU 1392 凸包模板题,求凸包周长
1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...
- poj 1113:Wall(计算几何,求凸包周长)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28462 Accepted: 9498 Description ...
- Wall---hdu1348(求凸包周长 模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 求凸包周长+2*PI*L: #include <stdio.h> #include ...
- POJ 1113 Wall(Graham求凸包周长)
题目链接 题意 : 求凸包周长+一个完整的圆周长. 因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 思路 : 求出凸包来,然后加上圆的周长 #include <stdi ...
- hdu 1392:Surround the Trees(计算几何,求凸包周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1348:Wall(计算几何,求凸包周长)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1392 Surround the Trees (Graham求凸包周长)
题目链接 题意 : 让你找出最小的凸包周长 . 思路 : 用Graham求出凸包,然后对每条边求长即可. Graham详解 #include <stdio.h> #include < ...
- poj1113Wall 求凸包周长 Graham扫描法
#include<iostream> #include<algorithm> #include<cmath> using namespace std; typede ...
随机推荐
- linux系列(二十):find命令
1.命令格式 find pathname -options [-print -exec -ok ...] 2.命令功能 用于在文件树种查找文件,并作出相应的处理 3.命令参数 pathname: fi ...
- ubuntu中防火墙iptables配置
特别说明:此文章完全转载于https://www.cnblogs.com/EasonJim/p/6851007.html 1.查看系统是否安装防火墙 root@localhost:/usr# whic ...
- 数据结构实验之查找一:二叉排序树 (SDUT 3373)
二叉排序树(Binary Sort Tree),又称二叉查找树(Binary Search Tree),也称二叉搜索树. #include <stdio.h> #include <s ...
- Python3 内置http.client,urllib.request及三方库requests发送请求对比
如有任何学习问题,可以添加作者微信:lockingfree 更多学习资料请加QQ群: 822601020获取 HTTP,GET请求,无参 GET http://httpbin.org/get Pyth ...
- 激活 phpstorm2019.1 win10
首先添加以下内容到c:\windows\system32\drivers\etc\hosts 文件 0.0.0.0 account.jetbrains.com 0.0.0.0 www.jetbrain ...
- [RK3399] 汇顶gt9xx触摸屏在RK原始代码调试
CPU:RK3399 系统:Android 7.1 触摸屏:1024x768 8inch 触摸IC:GT9271 基于RK3399,从瑞芯微服务器更新到最新的 Android 7.1 代码中,瑞芯 ...
- 使用PHP实现查找附近的人
https://zhuanlan.zhihu.com/p/31380780 LBS(基于位置的服务) 查找附近的人有个更大的专有名词叫做LBS(基于位置的服务),LBS是指是指通过电信移动运营商的无线 ...
- leetcode 143. Reorder List 、86. Partition List
143. Reorder List https://www.cnblogs.com/grandyang/p/4254860.html 先将list的前半段和后半段分开,然后后半段进行逆序,然后再连接 ...
- SpringBoot之返回json数据
一.创建一个springBoot个项目 二.编写实体类 /** * 返回Json数据实体类 */ public class User { private int id; private String ...
- paint之文字示例
package com.loaderman.customviewdemo; import android.content.Context; import android.graphics.Canvas ...