hdu 3255 Farming(矩形面积并 多种矩形)
来源:互联网 发布:网络巫师泰剧中字4 编辑:程序博客网 时间:2024/04/30 07:13
Farming
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 588 Accepted Submission(s): 151
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
Source
2009 Asia Regional Ningbo Online
Recommend
wujianhua
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3255
题意:在一块地上种蔬菜,对于同一块地蔬菜价值高的一定是最后存活,求最后的蔬菜总值,也就是不同的矩形覆盖,有的矩形肯定在最上面。。。
分析:其实跟矩形面积并的求法没多大区别,只要开一个多维数组来统计每一种蔬菜就行,先把蔬菜按值大小排序,方便处理,然后对于一个区间,如果被一种蔬菜覆盖,那么这种蔬菜的就覆盖整个区间,还要减去覆盖这个区间大于它 的蔬菜,对于小于它的蔬菜则全部置零,要不就wa了、、、
代码:
#include<cstdio>#include<iostream>#include<algorithm>#define ls rt<<1#define rs rt<<1|1#define lson l,m,ls#define rson m,r,rsusing namespace std;const int mm=66666;const int mn=mm<<2;struct seg{ int x,y1,y2,c,v;}g[mm];int t[mn][5],sum[mn][5],p[5],q[5];int y[mm];int L,R,C,val,T;void build(int n){ while(n--)for(int i=0;i<T;++i)t[n][i]=sum[n][i]=0;}void updata(int l,int r,int rt){ if(L<=y[l]&&R>=y[r])t[rt][C]+=val; else { int m=(l+r)>>1; if(L<y[m])updata(lson); if(R>y[m])updata(rson); } int i,j; for(i=T-1;i>=0;--i) if(t[rt][i]) { sum[rt][i]=y[r]-y[l]; for(j=i+1;j<T;++j) sum[rt][i]-=sum[rt][j]; for(j=0;j<i;++j)sum[rt][j]=0; break; } else if(l>=r)sum[rt][i]=0; else sum[rt][i]=sum[ls][i]+sum[rs][i];}bool cmp(seg a,seg b){ return a.x<b.x;}int main(){ int i,j,k,n,m,t,cs=0; __int64 ans; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&T); for(i=0;i<T;++i)scanf("%d",&p[i]),y[i]=i; for(i=0;i<T;++i) for(j=i+1;j<T;++j) if(p[i]>p[j])swap(y[i],y[j]),swap(p[i],p[j]); for(i=0;i<T;++i)q[y[i]]=i; for(i=0;i<n;++i) { scanf("%d%d%d%d%d",&g[i].x,&y[i],&g[i+n].x,&y[i+n],&g[i].c); g[i+n].c=g[i].c=q[g[i].c-1]; g[i].y1=y[i],g[i].y2=y[i+n],g[i].v=1; g[i+n].y1=y[i],g[i+n].y2=y[i+n],g[i+n].v=-1; } sort(y,y+n+n); sort(g,g+n+n,cmp); for(m=i=0;i<n+n;++i) if(y[m]<y[i])y[++m]=y[i]; for(ans=i=0;i<n+n;++i) { L=g[i].y1,R=g[i].y2,C=g[i].c,val=g[i].v; updata(0,m,1); if(g[i].x<g[i+1].x) for(j=0;j<T;++j) ans+=(__int64)(g[i+1].x-g[i].x)*(__int64)sum[1][j]*(__int64)p[j]; } printf("Case %d: %I64d\n",++cs,ans); } return 0;}
- hdu 3255 Farming(矩形面积并 多种矩形)
- HDU 3265(矩形面积并-分割矩形)
- HDU 1542(矩形面积并)
- hdu 1542 Atlantis(矩形面积并)
- HDU 1542 Atlantis(矩形面积并)
- HDU 1542 Atlantis (矩形面积并)
- hdu 1542 矩形面积并
- HDU 4419 矩形面积并
- hdu 4419 矩形面积并
- hdu 1542 矩形面积并
- hdu 4419 Colourful Rectangle(矩形面积并)
- HDU 4052 Adding New Machine(矩形面积并)
- HDU 1542 Atlantis(线段树求矩形面积并)
- hdu 1542 矩形面积并(扫描线+线段树)
- HDU 1542 Atlantis(线段树求矩形面积并)
- HDU-1264 Counting Squares(矩形面积并模板)
- HDU 1542 Atlantis(矩形并的面积)
- hdu 1542 (线段树求矩形面积并)
- 判断adodb php执行insert或update是否成功
- 针对网上流传的"Android 再按一次后退键退出应用程序"方法改正
- web开发技术初探
- Struts2让一个类成为一个Action的3种方式
- asp.net:web.config详解
- hdu 3255 Farming(矩形面积并 多种矩形)
- Qt内存管理
- 小猫丢了后
- 从决策树学习 谈到贝叶斯分类算法
- eclipse在线安装hibernatetools
- listview实现下拉刷新
- 关于 hibernate 逻辑删除 默认查询过滤条件问题(java set 条件)
- VI常用命令整理--转载
- 目标管理SMART原则