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[25],point[25],tubao[25];
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=1000000;
        for(int i=0;i<n;i++)scanf("%lf%lf%lf%lf",&tr[i].x,&tr[i].y,&tr[i].v,&tr[i].l);
        for(int i=0;i<(1<<n);i++){
            length=tot=top=rem=tempdis=wei=0;
            for(int j=0;j<n;j++){
                if(i&(1<<j))point[++tot]=tr[j],rem++;
                else length+=tr[j].l,wei+=tr[j].v;
            }
            sort(point+1,point+1+tot);
            for(int j=1;j<=tot;j++){
                while(top>1&&cross(tubao[top],point[j],tubao[top-1])<-eps)top--;
                tubao[++top]=point[j];
            }k=top;
            for(int j=tot-1;j>=1;j--){
                while(top>k&&cross(tubao[top],point[j],tubao[top-1])<-eps)top--;
                tubao[++top]=point[j];
            }
            for(int j=1;j<top;j++)tempdis+=dis(tubao[j]-tubao[j+1]);
            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=0;j<n;j++)if(!(ans&(1<<j)))printf(" %d",j+1);
        printf("\nExtra wood: %.2lf\n\n",remwei);
    }
}

原文地址:https://www.cnblogs.com/SiriusRen/p/9383102.html

时间: 2024-08-09 14:20:58

POJ 1873 计算几何的相关文章

POJ 1873

按位枚举,按最小价值,最小砍掉树剪枝就好了. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int MAXN=20; const int inf=190000000; int n,l; int st[MAXN],stop,cnt; int ans[MA

poj 1873 凸包+枚举

The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6198   Accepted: 1744 Description Once upon a time, in a faraway land, there lived a king. This king owned a small collection of rare and valuable trees, which had been

POJ 2398 计算几何+二分+排序

Toy Storage Time Limit: 1000MS  Memory Limit: 65536K Total Submissions: 3953  Accepted: 2334 Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box t

POJ 3304 计算几何

Segments Time Limit: 1000MS  Memory Limit: 65536K Total Submissions: 9564  Accepted: 2943 Description Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on

poj 1410 计算几何

1 /** 2 注意: 千万得小心..就因为一个分号,调了一个晚上... 3 **/ 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 struct point { 8 int x,y; 9 }; 10 11 struct line{ 12 point a; 13 point b; 14 }; 15 line l,lt;//l 直线 lt 矩形的边 16 int x1,x2,y1,y2; 17

poj 2653 计算几何

1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5 #include <cstdio> 6 using namespace std; 7 struct point { 8 double x,y; 9 }; 10 point be[100005],en[100005]; 11 int ans[100005]; 12 int re

poj 2398 计算几何

1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <algorithm> 5 using namespace std; 6 7 struct point{ 8 int x,y; 9 }; 10 11 struct line{ 12 point a,b; 13 }; 14 line lline[5005]; 15 16 int cnt[5005]; 17 int re

poj 1269 计算几何

1 /** 2 判断直线位置关系 3 **/ 4 #include <iostream> 5 #include <cmath> 6 #include <cstdio> 7 using namespace std; 8 struct point { 9 double x,y; 10 point(double x=0,double y=0):x(x),y(y){} 11 }; 12 13 typedef point Vector; 14 15 Vector operator

POJ 2318 计算几何+二分

TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10425 Accepted: 5002 Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away when