思路:

二进制枚举一下要删哪些点

求个凸包,算一下贡献

//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);
}
}

最新文章

  1. linQ学习笔记之一
  2. Materialize - 响应式 Material Design 框架
  3. No.6__C#
  4. HDFS用户指南
  5. Flask 快速入门
  6. (六)Angularjs - 启动引导
  7. AC自己主动机
  8. 关于JS的时间控制实现动态效果及实例操作
  9. JAVA面试一
  10. Qt: QAction在QToolBar中快捷键行为注意事项
  11. Unity3D学习笔记(二十二):ScrollView和事件接口
  12. Python【OS】模块
  13. Xilinx Altera FPGA中的逻辑资源(Slices VS LE)比较
  14. consul 小結
  15. fn project 试用之后的几个问题
  16. 从头认识java-14.4 Java提供的数组的有用功能(2)
  17. svn_学习_01_TortoiseSVN使用教程
  18. 应该知道的Linux技巧(转载)
  19. HTML head元素
  20. CSS动画的性能分析和浏览器GPU加速

热门文章

  1. 深入理解PHP之strpos
  2. 在vue中使用echars不能自适应的解决方法
  3. [bzoj4726][POI2017][Sabota?] (树形dp)
  4. Crackme3 破解教程
  5. 第一个Maven工程的目录结构和文件内容及联网问题
  6. hdu poj KMP简单题目总结
  7. [K/3Cloud]屏蔽页签的关闭按钮
  8. 文化之旅 2012年NOIP全国联赛普及组
  9. JRobin绘制指定时间段的流量图
  10. T1002 搭桥 codevs