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 ...
随机推荐
- 【Codeforces 1036C】Classy Numbers
[链接] 我是链接,点我呀:) [题意] 让你求出只由3个非0数字组成的数字在[li,ri]这个区间里面有多少个. [题解] 只由3个非0数字组成的数字在1~10^18中只有60W个 dfs处理出来之 ...
- JavaSE 学习笔记之新特性之泛型(二十)
泛型:jdk1.5版本以后出现的一个安全机制.表现格式:< > 好处: 1:将运行时期的问题ClassCastException问题转换成了编译失败,体现在编译时期,程序员就可以解决问题. ...
- mybatis写当天 当月的数据 时间段数据https://www.cnblogs.com/xzjf/p/7600533.html
mybatis写当天 当月的数据 时间段数据----https://www.cnblogs.com/xzjf/p/7600533.html
- nyoj 63 小猴子下落
小猴子下落 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 有一颗二叉树,最大深度为D,且所有叶子的深度都相同.所有结点从左到右从上到下的编号为1,2,3,····· ...
- empty array & Array.from
empty array bug const duplicationArray = (arr = [], times = 2, debug = false) => { let result = [ ...
- leetcode算法学习----155. 最小栈(MinStack )
下面题目是LeetCode算法155题: https://leetcode.com/problems/min-stack/ 题目1:最小函数min()栈 设计一个支持 push,pop,top 操作, ...
- 洛谷—— P3385 【模板】负环
题目描述 暴力枚举/SPFA/Bellman-ford/奇怪的贪心/超神搜索 输入输出格式 输入格式: 第一行一个正整数T表示数据组数,对于每组数据: 第一行两个正整数N M,表示图有N个顶点,M条边 ...
- CentOS redis安装配置
编译依赖安装 yum install gcc-c++ yum install -y tcl 安装步骤 下载:wget http://download.redis.io/releases/redis-5 ...
- BC #62 div1 02
/* 数位DP题,设dp[n][k][j]为前n位最后一位是k时mod为j的个数.操作都相同,可以使用矩阵加速.本来对于每一位是7*10,可以把它压向一个向量. 加速矩阵为70*70,再加一维计算前缀 ...
- jQuery.data() 存储数据
jQuery.data() 的实现方式 jQuery.data() 的作用是为普通对象或 DOM Element 附加数据. 以下将分三个部分分析事实上现方式: 1. 用name和value为对象附加 ...