HDU 3634 City Planning

来源:互联网 发布:马穆鲁克王朝知乎 编辑:程序博客网 时间:2024/06/06 07:18

City Planning

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 376 Accepted Submission(s): 149


Problem Description
After many years, the buildings in HDU has become very old. It need to rebuild the buildings now. So Mr dragon (the president of HDU's logistics department ) ask Mr Wan (a very famous engineer) for help.
Mr Wan only draw one building on a construction design drawings(all the buildings are rectangle and each edge of buildings' is paraller or perpendicular to others buildings' edge ). And total draw n drawings (all the drawings have same width and length . And bottomleft point is (0, 0)). Due to possible overlap of conditions, so when they build a new building, they should to remove all the overlapping part of it. And for each building, HDU have a jury evaluate the value per unit area. Now Mr dragon want to know how to arrange the order of build these buildings can make the highest value.

Input
The first line of input is a number T which indicate the number of cases . (1 < T < 3000);
Each test case will begin with a single line containing a single integer n (where 1 <= n <= 20).
Next n line will contain five integers x1, y1, x2, y2 ,value . x1,y1 is bottomleft point and x2,y2 is topright point , value is the value of the buildings' unit area.((0 <= x1, y1, x2, y2 <= 10000) (x1 < x2, && y1 < y2) (1 <= value <= 22)

Output
For each case. You just ouput the highest value in one line.

Sample Input
131 1 10 10 44 4 15 5 57 8 20 30 6

Sample Output
Case 1: 2047

Author
08052233

Source
2010 ACM-ICPC Multi-University Training Contest(19)——Host by HDU

Recommend
lcy
   这题转化后就是矩形的覆盖求面积问题,以前也遇到过这种问题,当时没有解决,今天又遇到了,这是专门考不会的啊。 我是看了论文后,才知道思路的。同样也建议大家看看相关方面的论文,就知道线段切割,矩形切割这回事了,就能做出此题。
主要思路就是就是要把覆盖的切割成其他的矩形,原矩形删除
论文地址:http://wenku.baidu.com/view/aea32d1aa8114431b90dd8b5.html
/*************************************************************** > File Name: 2.cpp > Author: SDUT_GYX > Mail: 2272902662@qq.com > Created Time: 2013/5/11 14:51:51 ************************************************************/#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <stdlib.h>using namespace std;#define N 100struct num{int x1,y1,x2,y2,val;}a[N],b[N];int top;int max(int x,int y){return x>y ? x:y;}int min(int x,int y){return x>y ? y:x;}int cmp(const void *e,const void *f){struct num *p1=(struct num *)e;struct num *p2=(struct num *)f;return (p1->val - p2->val);}int main(){ //  freopen("data1.in","r",stdin);void add(int x1,int y1,int x2,int y2,int val);void del(int i);int i,j,n,m,t,T;T=1;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<=n-1;i++){scanf("%d %d %d %d %d",&a[i].x1,&a[i].y1,&a[i].x2,&a[i].y2,&a[i].val);}qsort(a,n,sizeof(a[0]),cmp);for(i=0,top=0;i<=n-1;i++){    for(j=0;j<=top-1;){if(b[j].x1>=a [i].x2||b[j].x2<=a[i].x1||b[j].y1>=a[i].y2||b[j].y2<=a[i].y1){ j++;continue;}int k1=max(b[j].x1,a[i].x1);int k2=min(b[j].x2,a[i].x2);if(b[j].x1<k1){ add(b[j].x1,b[j].y1,k1,b[j].y2,b[j].val);}if(b[j].x2>k2){ add(k2,b[j].y1,b[j].x2,b[j].y2,b[j].val);}int k3=max(b[j].y1,a[i].y1);int k4=min(b[j].y2,a[i].y2);if(k3>b[j].y1){ add(k1,b[j].y1,k2,k3,b[j].val);}if(k4<b[j].y2){ add(k1,k4,k2,b[j].y2,b[j].val);    }del(j);}    b[top].x1=a[i].x1;b[top].y1=a[i].y1;b[top].x2=a[i].x2;b[top].y2=a[i].y2;b[top++].val=a[i].val;}long long int s=0;for(i=0;i<=top-1;i++){s+=(long long int)(b[i].x2 - b[i].x1)*(long long int)(b[i].y2 - b[i].y1)*(long long int)b[i].val;}printf("Case %d: ",T++);cout<<s<<endl;}return 0;}void add(int x1,int y1,int x2,int y2,int val){b[top].x1 = x1;b[top].y1 = y1;b[top].x2 = x2;b[top].y2 = y2;b[top++].val = val;}void del(int i){b[i].x1 = b[top-1].x1;b[i].y1 = b[top-1].y1;b[i].x2 = b[top-1].x2;b[i].y2 = b[top-1].y2;b[i].val = b[top-1].val;top--;}

 
 
 
 
原创粉丝点击