POJ 1873 计算几何
思路:
二进制枚举一下要删哪些点
求个凸包,算一下贡献
//By SiriusRen
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define eps 1e-9
int n,cases,top,tot,k,rem,ansrem,ans;
double length,tempdis,wei,answei,remwei;
struct Tree{double x,y,v,l;}tr[],point[],tubao[];
bool operator<(Tree a,Tree b){if(abs(a.x-b.x)<eps)return a.y<b.y;return a.x<b.x;}
double operator*(Tree a,Tree b){return a.x*b.y-a.y*b.x;}
Tree operator-(Tree a,Tree b){Tree c;c.x=a.x-b.x;c.y=a.y-b.y;return c;}
double dis(Tree a){return sqrt(a.x*a.x+a.y*a.y);}
double cross(Tree a,Tree b,Tree c){return (a-c)*(b-c);}
int main(){
while(scanf("%d",&n)&&n){
answei=;
for(int i=;i<n;i++)scanf("%lf%lf%lf%lf",&tr[i].x,&tr[i].y,&tr[i].v,&tr[i].l);
for(int i=;i<(<<n);i++){
length=tot=top=rem=tempdis=wei=;
for(int j=;j<n;j++){
if(i&(<<j))point[++tot]=tr[j],rem++;
else length+=tr[j].l,wei+=tr[j].v;
}
sort(point+,point++tot);
for(int j=;j<=tot;j++){
while(top>&&cross(tubao[top],point[j],tubao[top-])<-eps)top--;
tubao[++top]=point[j];
}k=top;
for(int j=tot-;j>=;j--){
while(top>k&&cross(tubao[top],point[j],tubao[top-])<-eps)top--;
tubao[++top]=point[j];
}
for(int j=;j<top;j++)tempdis+=dis(tubao[j]-tubao[j+]);
if(tempdis<length){
if(wei<answei)answei=wei,ansrem=rem,ans=i,remwei=length-tempdis;
else if(wei==answei&&rem<ansrem)ansrem=rem,ans=i,remwei=length-tempdis;
}
}
printf("Forest %d\nCut these trees:",++cases);
for(int j=;j<n;j++)if(!(ans&(<<j)))printf(" %d",j+);
printf("\nExtra wood: %.2lf\n\n",remwei);
}
}
POJ 1873 计算几何的更多相关文章
- poj 1873 凸包+枚举
The Fortified Forest Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6198 Accepted: 1 ...
- ●POJ 1873 The Fortified Forest
题链: http://poj.org/problem?id=1873 题解: 计算几何,凸包 枚举被砍的树的集合.求出剩下点的凸包.然后判断即可. 代码: #include<cmath> ...
- POJ 1556 计算几何+最短路
代码1: #include<iostream> #include<stdio.h> #include<string> #include<string.h> ...
- POJ 1873 The Fortified Forest(凸包)题解
题意:二维平面有一堆点,每个点有价值v和删掉这个点能得到的长度l,问你删掉最少的价值能把剩余点围起来,价值一样求删掉的点最少 思路:n<=15,那么直接遍历2^15,判断每种情况.这里要优化一下 ...
- POJ 2954-Triangle(计算几何+皮克定理)
职务地址:POJ 2954 意甲冠军:三个顶点的三角形,给出,内部需求格点数. 思考:就像POJ 1265. #include <stdio.h> #include <math.h& ...
- POJ 1873 - The Fortified Forest 凸包 + 搜索 模板
通过这道题发现了原来写凸包的一些不注意之处和一些错误..有些错误很要命.. 这题 N = 15 1 << 15 = 32768 直接枚举完全可行 卡在异常情况判断上很久,只有 顶点数 &g ...
- 简单几何(凸包+枚举) POJ 1873 The Fortified Forest
题目传送门 题意:砍掉一些树,用它们做成篱笆把剩余的树围起来,问最小价值 分析:数据量不大,考虑状态压缩暴力枚举,求凸包以及计算凸包长度.虽说是水题,毕竟是final,自己状压的最大情况写错了,而且忘 ...
- The Fortified Forest - POJ 1873(状态枚举+求凸包周长)
题目大意:有个国王他有一片森林,现在他想从这个森林里面砍伐一些树木做成篱笆把剩下的树木围起来,已知每个树都有不同的价值还有高度,求出来砍掉那些树可以做成篱笆把剩余的树都围起来,要使砍伐的树木的价值最小 ...
- poj 1410 计算几何
/** 注意: 千万得小心..就因为一个分号,调了一个晚上... **/ #include <iostream> #include <algorithm> using name ...
随机推荐
- linux strings-在对象文件或二进制文件中查找可打印的字符串
推荐:更多Linux 文件查找和比较 命令关注:linux命令大全 strings命令在对象文件或二进制文件中查找可打印的字符串.字符串是4个或更多可打印字符的任意序列,以换行符或空字符结束. str ...
- Datatable 插入一行数据到第一行
var t = $('#passwdHOST').DataTable({ 'searching': true, 'ordering': false, 'autoWidth': false, dom: ...
- [bzoj1820][JSOI2010][Express Service 快递服务] (动态规划)
Description 「飞奔」快递公司成立之后,已经分别与市内许多中小企业公司签订邮件收送服务契约.由于有些公司是在同一栋大楼内,所以「飞奔」公司收件的地点(收件点)最多只有m点 (1, 2, …, ...
- Discuz论坛迁移需要修改的3个配置文件
需要修改的3个地方: \config\config_global.php \config\config_ucenter.php \uc_server\data\config.inc.php
- HDU1507 Uncle Tom's Inherited Land*
题目是跟 zoj1516是一样的,但多了匹配后的输出 详解zoj1516可见http://www.cnblogs.com/CSU3901130321/p/4228057.html #include & ...
- nyoj_127_星际之门(一)_201403282033
星际之门(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 公元3000年,子虚帝国统领着N个星系,原先它们是靠近光束飞船来进行旅行的,近来,X博士发明了星际之门 ...
- log4j2.xml 的配置 及使用
log4j2.xml配置 <?xml version="1.0" encoding="UTF-8"?> <Configuration > ...
- Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n
错误如下: 2017-09-19 15:05:24.659 INFO 9986 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refre ...
- TreeView获取目录下的所有文件
/// <summary> /// TreeView获取目录下的所有文件 /// </summary> /// <param name="tree"& ...
- Android实现一个自己定义相机的界面
我们先实现拍照button的圆形效果哈.Android开发中,当然能够找美工人员设计图片,然后直接拿进来.只是我们能够自己写代码实现这个效果哈.最经常使用的的是用layout-list实现图片的叠加, ...