Farming - HDU 3255 扫描线
来源:互联网 发布:魔卡幻想网络不给力 编辑:程序博客网 时间:2024/05/16 10:01
Farming
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1307 Accepted Submission(s): 385
Problem Description
You have a big farm, and you want to grow vegetables in it. You're too lazy to seed the seeds yourself, so you've hired n people to do the job for you.
Each person works in a rectangular piece of land, seeding one seed in one unit square. The working areas of different people may overlap, so one unit square can be seeded several times. However, due to limited space, different seeds in one square fight each other -- finally, the most powerful seed wins. If there are several "most powerful" seeds, one of them win (it does not matter which one wins).
There are m kinds of seeds. Different seeds grow up into different vegetables and sells for different prices.
As a rule, more powerful seeds always grow up into more expensive vegetables.
Your task is to calculate how much money will you get, by selling all the vegetables in the whole farm.
Each person works in a rectangular piece of land, seeding one seed in one unit square. The working areas of different people may overlap, so one unit square can be seeded several times. However, due to limited space, different seeds in one square fight each other -- finally, the most powerful seed wins. If there are several "most powerful" seeds, one of them win (it does not matter which one wins).
There are m kinds of seeds. Different seeds grow up into different vegetables and sells for different prices.
As a rule, more powerful seeds always grow up into more expensive vegetables.
Your task is to calculate how much money will you get, by selling all the vegetables in the whole farm.
Input
The first line contains a single integer T (T <= 10), the number of test cases.
Each case begins with two integers n, m (1 <= n <= 30000, 1 <= m <= 3).
The next line contains m distinct positive integers pi (1 <= pi <= 100), the prices of each kind of vegetable.
The vegetables (and their corresponding seeds) are numbered 1 to m in the order they appear in the input.
Each of the following n lines contains five integers x1, y1, x2, y2, s, indicating a working seeded a rectangular area with lower-left corner (x1,y1), upper-right corner (x2,y2), with the s-th kind of seed.
All of x1, y1, x2, y2 will be no larger than 106 in their absolute values.
Each case begins with two integers n, m (1 <= n <= 30000, 1 <= m <= 3).
The next line contains m distinct positive integers pi (1 <= pi <= 100), the prices of each kind of vegetable.
The vegetables (and their corresponding seeds) are numbered 1 to m in the order they appear in the input.
Each of the following n lines contains five integers x1, y1, x2, y2, s, indicating a working seeded a rectangular area with lower-left corner (x1,y1), upper-right corner (x2,y2), with the s-th kind of seed.
All of x1, y1, x2, y2 will be no larger than 106 in their absolute values.
Output
For each test case, print the case number and your final income.
Sample Input
21 1250 0 10 10 12 25 20 0 2 1 11 0 3 2 2
Sample Output
Case 1: 2500Case 2: 16
题意:在一个田地上会种植不用种类的作物,如果一个地方多次种植,会长出价值高的那种,问最后的收益是多少。
思路:将作物的价值看成是高,这样的话,就转换成了求长方体的体积。
AC代码如下:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;struct node1{ int l,r,lazy,sum[2];}tree[8000010];struct node2{ int l,r,h,f;}line[60100];struct node3{ int x1,x2,y1,y2,p;}area[30010];bool cmp(node2 a,node2 b){ return a.h<b.h;}int val[10];ll ans;int px[60010],point[2000010];void build(int o,int l,int r){ tree[o].l=l; tree[o].r=r; tree[o].lazy=0; tree[o].sum[1]=0;tree[o].sum[0]=px[r]-px[l-1]; if(l==r) return; int mi=(l+r)/2; build(o<<1,l,mi); build(o<<1|1,mi+1,r);;}void solve(int o){ if(tree[o].lazy>0) tree[o].sum[1]=tree[o].sum[0]; else { if(tree[o].l==tree[o].r) tree[o].sum[1]=0; else tree[o].sum[1]=tree[o<<1].sum[1]+tree[o<<1|1].sum[1]; }}void update(int o,int l,int r,int f){ if(tree[o].l==l && tree[o].r==r && tree[o].lazy+f>=0) { tree[o].lazy+=f; solve(o); return; } int mi=(tree[o].l+tree[o].r)/2; if(r<=mi) update(o<<1,l,r,f); else if(l>mi) update(o<<1|1,l,r,f); else { update(o<<1,l,mi,f); update(o<<1|1,mi+1,r,f); } solve(o);}int main(){ int T,n,m,t,i,j,k,num,len; scanf("%d",&T); for(t=1;t<=T;t++) { ans=0; scanf("%d%d",&n,&m); for(i=1;i<=m;i++) scanf("%d",&val[i]); for(i=1;i<=n;i++) { scanf("%d%d%d%d%d",&area[i].x1,&area[i].y1,&area[i].x2,&area[i].y2,&area[i].p); area[i].x1+=1000000; area[i].x2+=1000000; area[i].p=val[area[i].p]; } len=-1; for(i=1;i<=n;i++) { px[i*2-1]=area[i].x1; px[i*2]=area[i].x2; } sort(px+1,px+1+n*2); px[0]=-1; for(i=1;i<=n*2;i++) if(px[i]!=px[i-1]) { px[++len]=px[i]; point[px[i]]=len; } for(i=1;i<=n;i++) { area[i].x1=point[area[i].x1]; area[i].x2=point[area[i].x2]; } sort(val+1,val+1+m); for(k=1;k<=m;k++) { num=0; for(i=1;i<=n;i++) if(area[i].p>=val[k]) { num+=2; line[num-1].l=area[i].x1+1;line[num-1].r=area[i].x2;line[num-1].h=area[i].y2;line[num-1].f=-1; line[num].l=area[i].x1+1;line[num].r=area[i].x2;line[num].h=area[i].y1;line[num].f=1; } sort(line+1,line+1+num,cmp); build(1,1,len); for(i=1;i<num;i++) { update(1,line[i].l,line[i].r,line[i].f); ans+=(ll)(val[k]-val[k-1])*tree[1].sum[1]*(line[i+1].h-line[i].h); } } printf("Case %d: %I64d\n",t,ans); }}
0 0
- hdu 3255 Farming(扫描线)
- Farming - HDU 3255 扫描线
- hdu 3255 Farming 长方体扫描线
- HDU 3255 Farming(线段树:扫描线)
- hdu 3255 Farming(扫描线、求立方体交)
- hdu 3255 Farming (线段树扫描线球体积并)
- hdu 3544 Farming(扫描线)
- hdu 3255 Farming
- HDU 3255 Farming
- Hdu 3255 Farming
- HDU 3255 Farming
- HDU-3255-Farming
- HDU 3255 Farming
- HDU 3255 Farming
- HDU 3255 Farming
- HDU_3255 Farming 扫描线求面积并
- HDU3255 Farming(线段树+扫描线)
- Hdu 3255 Farming(长方形体积并)
- Bruce Eckel:编程生涯
- uva 10014 Simple calculations
- Javascript 异步加载详解
- Linux下图形化串口调试工具xgcom安装
- JSONP 跨域解析
- Farming - HDU 3255 扫描线
- Mysql 索引
- MySQL启动不起来和关闭不了的问题记录
- JAVA中,List<Interger>集合怎么删除特定值的元素,不是根据下标
- CentOS的额外软件仓库
- 如何设置eclipse中的文件的默认打开方式
- c/c++深入篇之内存分配与内存对齐的探讨
- SAP VA01屏幕增强(user-exit)
- https单向/双向认证的tomcat配置攻略