Farming
Problem Description
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
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
Sample Input
2
1 1
25
0 0 10 10 1
2 2
5 2
0 0 2 1 1
1 0 3 2 2
Sample Output
Case 1: 2500
Case 2: 16
#include<cstdio>
#include<iostream>
#include<algorithm>
#define ls rt<<1
#define rs rt<<1|1
#define lson l,m,ls
#define rson m,r,rs
using namespace std;
const int mm=;
const int mn=mm<<;
struct seg
{
int x,y1,y2,c,v;
} g[mm];
int t[mn][],sum[mn][],p[],q[];
int y[mm];
int L,R,C,val,T;
void build(int n)
{
while(n--)for(int i=; i<T; ++i)t[n][i]=sum[n][i]=;
}
void updata(int l,int r,int rt)
{
if(L<=y[l]&&R>=y[r])t[rt][C]+=val;
else
{
int m=(l+r)>>;
if(L<y[m])updata(lson);
if(R>y[m])updata(rson);
}
int i,j;
for(i=T-; i>=; --i)
if(t[rt][i])
{
sum[rt][i]=y[r]-y[l];
for(j=i+; j<T; ++j)
sum[rt][i]-=sum[rt][j];
for(j=; j<i; ++j)sum[rt][j]=;
break;
}
else if(l>=r)sum[rt][i]=;
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=;
__int64 ans;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&T);
for(i=; i<T; ++i)scanf("%d",&p[i]),y[i]=i;
for(i=; i<T; ++i)
for(j=i+; j<T; ++j)
if(p[i]>p[j])swap(y[i],y[j]),swap(p[i],p[j]);
for(i=; i<T; ++i)q[y[i]]=i;
for(i=; 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-];
g[i].y1=y[i],g[i].y2=y[i+n],g[i].v=;
g[i+n].y1=y[i],g[i+n].y2=y[i+n],g[i+n].v=-;
}
sort(y,y+n+n);
sort(g,g+n+n,cmp);
for(m=i=; i<n+n; ++i)
if(y[m]<y[i])y[++m]=y[i];
for(ans=i=; i<n+n; ++i)
{
L=g[i].y1,R=g[i].y2,C=g[i].c,val=g[i].v;
updata(,m,);
if(g[i].x<g[i+].x)
for(j=; j<T; ++j)
ans+=(__int64)(g[i+].x-g[i].x)*(__int64)sum[][j]*(__int64)p[j];
}
printf("Case %d: %I64d\n",++cs,ans);
}
return ;
}
Farming的更多相关文章
- hdu 3255 Farming(扫描线)
题目链接:hdu 3255 Farming 题目大意:给定N个矩形,M个植物,然后给定每一个植物的权值pi,pi表示种植物i的土地,单位面积能够收获pi,每一个矩形给定左下角和右上角点的坐标,以及s, ...
- unity疯狂牧场完整项目源码 - Frenzy Farming time management game kit V1.0
You will love this game kit! Have you ever wondered what it would be like to run your own farm? Look ...
- HDU 3255 Farming (线段树+扫面线,求体积并)
题意:在一块地上种蔬菜,每种蔬菜有个价值.对于同一块地蔬菜价值高的一定是最后存活,求最后的蔬菜总值. 思路:将蔬菜的价值看做高度的话,题目就转化成求体积并,这样就容易了. 与HDU 3642 Get ...
- HDU 3255 Farming
矩形面积并变形,一层一层的算体积 #include<cstdio> #include<cstring> #include<cmath> #include<ma ...
- 线段树 hdu3255 Farming
做了这么多扫描线的题,,基本都是一个思路. 改来改去,,无非就是维护的节点的内容以及push_up越写越复杂了而已 首先将价格排序处理一下编号,变成编号越大的powerfol越大 然后后面加入扫描线的 ...
- 【转】windows和linux中搭建python集成开发环境IDE
本系列分为两篇: 1.[转]windows和linux中搭建python集成开发环境IDE 2.[转]linux和windows下安装python集成开发环境及其python包 3.windows和l ...
- blade and soul zone overview
The world of Blade and Soul, is a vast extension of land containing two continents (the Southern Con ...
- 【英语魔法俱乐部——读书笔记】 3 高级句型-简化从句&倒装句(Reduced Clauses、Inverted Sentences) 【完结】
[英语魔法俱乐部——读书笔记] 3 高级句型-简化从句&倒装句(Reduced Clauses.Inverted Sentences):(3.1)从属从句简化的通则.(3.2)形容词从句简化. ...
- [SharePoint] SharePoint 错误集 2
1 Run command “New-SPConfigurationDatabase" Feature Description: error message popup after run ...
随机推荐
- codility上的问题 (22)
问题描述: 用1 * 1, 1 * 2的矩形覆盖一个n行m列的矩形,问有多少种方法. 数据范围 : n [1..10^6], m [ 1..7] 要求复杂度: 时间 O(log(n) * 8 ^m ...
- heritrix 3.2.0 -- 环境搭建
heritrix作为一个比较经典的开源爬虫,写这篇文章目的是因为,3.X之后的heritrix的介绍以及配置的文章比较少了. heritrix 3.x 以后使用maven 2配置jar包引用,但是总是 ...
- Unix/Linux环境C编程入门教程(39) shell命令之系统管理
df命令 用于检测文件系统的磁盘空间占用和空余情况,可以显示所有文件系统对节点和磁盘块的使用情况.命令的使用格式如下: df [选项] 常用参数及含义如下表所示. df -a:显示所有文件系统的磁盘 ...
- RBL, UBL, Uboot的关系
RBL, UBL, Uboot的关系 1)RBL=ROM Bootloader,UBL=user Bootloader. 2)RBL为TI固化在芯片ROM中的bootloader,OMAP上电启动过后 ...
- 2013成都网赛 G(x) (HDU 4733)
G(x) 思路: 首先搞清楚每个位置上的值有什么意义, 如果第i位的值为1则 第i位与第i+1位不同,反之相同. 然后考虑s1和s2为什么会不一样, 这是由于x+1后比特位进位导致的,于是得出一个性质 ...
- 《Two Days DIV + CSS》读书笔记——CSS选择器
1.1.2 CSS选择器 CSS 选择器最基本的有四种:标签选择器.ID 选择器.类选择器.通用选择器. [标签选择器] 一个完整的 HTML 页面由很多不同的标签组成,而标签选择器,则是决定哪些标签 ...
- 【iOS开发-66】QQ设置界面的案例:利用storyboard开发静态的tableView界面,核心是Static Cells
(1)效果 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2Vpc3ViYW8=/font/5a6L5L2T/fontsize/400/fill/I0JB ...
- 高仿拉手网底部菜单实现FragmentActivity+Fragment+RadioGroup
先把欢迎页和引导页的代码上传了http://download.csdn.net/detail/u013134391/7183787不要积分的. 底部菜单条实如今4.0曾经都是用tabhost.如今基本 ...
- 使用批处理bat作为日期系统日期的前三天
在管理server它经常是依据一天来推断载日期系统日志文件,例如,上周五,周一的需要上传日志.上传日志的日期前一天,日志文件命名的日期.这需要获得的日期的前三天.或之前n当天日期. 批量绑定vbs可以 ...
- sql 参数
sqlserver :传参数是“@” oracle:是“:” mysql:是“?”