POJ 1873 计算几何
2024-09-04 04:22:57
思路:
二进制枚举一下要删哪些点
求个凸包,算一下贡献
//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);
}
}
最新文章
- linQ学习笔记之一
- Materialize - 响应式 Material Design 框架
- No.6__C#
- HDFS用户指南
- Flask 快速入门
- (六)Angularjs - 启动引导
- AC自己主动机
- 关于JS的时间控制实现动态效果及实例操作
- JAVA面试一
- Qt: QAction在QToolBar中快捷键行为注意事项
- Unity3D学习笔记(二十二):ScrollView和事件接口
- Python【OS】模块
- Xilinx Altera FPGA中的逻辑资源(Slices VS LE)比较
- consul 小結
- fn project 试用之后的几个问题
- 从头认识java-14.4 Java提供的数组的有用功能(2)
- svn_学习_01_TortoiseSVN使用教程
- 应该知道的Linux技巧(转载)
- HTML head元素
- CSS动画的性能分析和浏览器GPU加速