POJ 1873 The Fortified Forest(凸包)题解
题意:二维平面有一堆点,每个点有价值v和删掉这个点能得到的长度l,问你删掉最少的价值能把剩余点围起来,价值一样求删掉的点最少
思路:n<=15,那么直接遍历2^15,判断每种情况。这里要优化一下,如果价值比当前最优大了continue。POJ的G++输出要用%f...orz,还是乖乖用C++...
代码:
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;
const int maxn = + ;
const int MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
struct node{
double x, y, l;
int v, id;
}p[maxn], s[maxn], q[maxn];
int n, top;
double dis(node a, node b){
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool cmp(node a, node b){
double A = atan2((a.y - p[].y), (a.x - p[].x));
double B = atan2((b.y - p[].y), (b.x - p[].x));
if(A != B) return A < B;
else{
return dis(a, p[]) < dis(b, p[]);
}
}
double cross(node a, node b, node c){ //(a->b)X(a->c)
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}
void solve(){
int pos = ;
for(int i = ; i <= n; i++){
if(p[i].y < p[pos].y || (p[i].y == p[pos].y && p[i].x < p[pos].x)){
pos = i;
}
}
swap(p[], p[pos]);
sort(p + , p + n + , cmp);
s[] = p[], s[] = p[];
top = ;
for(int i = ; i <= n; i++){
while(top >= && cross(s[top - ], p[i], s[top]) >= ){
top--;
}
s[++top] = p[i];
}
}
double need(double len){
if(n <= ) return len;
if(n == ){
return len - 2.0 * dis(p[], p[]);
}
solve();
double Need = ;
for(int i = ; i < top; i++){
Need += dis(s[i], s[i + ]);
}
Need += dis(s[top], s[]);
return len - Need;
}
int main(){
int N, ca = ;
while(~scanf("%d", &N) && N){
for(int i = ; i < N; i++){
scanf("%lf%lf%d%lf", &q[i].x, &q[i].y, &q[i].v, &q[i].l);
q[i].id = i + ;
}
int sz = , que[], tempQue[];
int MinValue = INF;
double ans = ;
for(int i = ; i < ( << N); i++){
int num = , value = ;
double len = ;
n = ;
for(int j = ; j < N; j++){
if(i & ( << j)){
p[++n] = q[j];
}
else{
value += q[j].v;
len += q[j].l;
tempQue[num] = q[j].id;
num++;
}
}
if(value > MinValue) continue;
double tmp = need(len);
if(tmp < ) continue;
if(value < MinValue || (value == MinValue && num < sz)){
MinValue = value;
ans = tmp;
sz = num;
for(int j = ; j < num; j++){
que[j] = tempQue[j];
}
}
}
if(ca != ) printf("\n");
printf("Forest %d\n", ca++);
printf("Cut these trees: ");
for(int i = ; i < sz; i++){
printf("%d ", que[i]);
}
printf("\n");
printf("Extra wood: %.2lf\n", ans);
}
return ;
}
POJ 1873 The Fortified Forest(凸包)题解的更多相关文章
- POJ 1873 The Fortified Forest [凸包 枚举]
The Fortified Forest Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6400 Accepted: 1 ...
- POJ 1873 - The Fortified Forest 凸包 + 搜索 模板
通过这道题发现了原来写凸包的一些不注意之处和一些错误..有些错误很要命.. 这题 N = 15 1 << 15 = 32768 直接枚举完全可行 卡在异常情况判断上很久,只有 顶点数 &g ...
- POJ 1873 The Fortified Forest 凸包 二进制枚举
n最大15,二进制枚举不会超时.枚举不被砍掉的树,然后求凸包 #include<stdio.h> #include<math.h> #include<algorithm& ...
- 简单几何(凸包+枚举) POJ 1873 The Fortified Forest
题目传送门 题意:砍掉一些树,用它们做成篱笆把剩余的树围起来,问最小价值 分析:数据量不大,考虑状态压缩暴力枚举,求凸包以及计算凸包长度.虽说是水题,毕竟是final,自己状压的最大情况写错了,而且忘 ...
- POJ 1873 The Fortified Forest(枚举+凸包)
Description Once upon a time, in a faraway land, there lived a king. This king owned a small collect ...
- ●POJ 1873 The Fortified Forest
题链: http://poj.org/problem?id=1873 题解: 计算几何,凸包 枚举被砍的树的集合.求出剩下点的凸包.然后判断即可. 代码: #include<cmath> ...
- POJ 1873 The Fortified Forest
题意:是有n棵树,每棵的坐标,价值和长度已知,要砍掉若干根,用他们围住其他树,问损失价值最小的情况下又要长度足够围住其他树,砍掉哪些树.. 思路:先求要砍掉的哪些树,在求剩下的树求凸包,在判是否可行. ...
- poj1873 The Fortified Forest 凸包+枚举 水题
/* poj1873 The Fortified Forest 凸包+枚举 水题 用小树林的木头给小树林围一个围墙 每棵树都有价值 求消耗价值最低的做法,输出被砍伐的树的编号和剩余的木料 若砍伐价值相 ...
- Uva5211/POJ1873 The Fortified Forest 凸包
LINK 题意:给出点集,每个点有个价值v和长度l,问把其中几个点取掉,用这几个点的长度能把剩下的点围住,要求剩下的点价值和最大,拿掉的点最少且剩余长度最长. 思路:1999WF中的水题.考虑到其点的 ...
随机推荐
- windows编程之Windows Shell 编程
参考书<VC++ Windows Shell Programming> 这里仅仅是记录下该资源,推荐到下文列出的连接进行查看 用VC++ 进行Windows Shell 扩展编成 ...
- C++中overload(重载),override(覆盖),overwrite(重写/覆写)的区别
#include <cstdio> #include <cstdlib> class Base { public: #pragma region MyRegion1 //函数重 ...
- <<Natural Language Inference over Interaction Space >> 句子匹配
模型结构 code :https://github.com/YichenGong/Densely-Interactive-Inference-Network 首先是模型图: Embedding Lay ...
- 安装模块时报错“error: Microsoft Visual C++ 14.0 is required…”
安装pymssql时报错:在安装的过程中遇到了“error: Microsoft Visual C++ 14.0 is required…” 解决办法: 进入https://www.lfd.uci.e ...
- sql server 中后缀为.mdf的文件是干什么用的??
在微软的SQL Server 2000 数据库有三种类型的文件: 1)主要数据文件(扩展名.mdf是 primary data file 的缩写) 主要数据文件包含数据库的启动信息,并指向数据库中的其 ...
- python 解码json数据并在一个OrderdDict中保留其顺序
一般来讲,JSON 解码会根据提供的数据创建dicts 或lists.如果你想要创建其他类型的对象,可以给json.loads() 传递object_pairs_hook 或object_hook 参 ...
- JAVA 中的 Collection 和 Map 以及相关派生类的概念
JAVA中Collection接口和Map接口的主要实现类 Collection接口 Collection是最基本的集合接口,一个Collection代表一组Object,即Collection的 ...
- python中从键盘输入内容的方法raw_input()和input()的区别
raw_input()输出结果都是字符串 Input()输入什么内容,输出就是什么内容
- react+redux+react-router+node.js 开发实时聊天App 学习记录
一.课程导学 1.React 主要解决的是UI层的问题,应用的状态需要借助Redux等状态管理. 2.前端React + antd-mobile UI组件库 + Redux 状态管理库 + Rea ...
- 设置 DNS,防止 DNS 污染,清除 DNS 缓存ipconfig /flushdns
设置 DNS,防止 DNS 污染选中“使用下面的 DNS 服务器地址”,“首选 DNS 服务器”中填写 8.8.8.8,“备用 DNS 服务器”中填写 8.8.4.4,然后点击“确定”按钮清除 DNS ...