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 ...
随机推荐
- hihoCoder 1098
题目大意:n 个城市由 m 条边连接,每条边有权值,求将所有城市连接起来时的最小权值和. 代码: #include<iostream> #include<cstdio> #in ...
- Unity 屏幕适配小脚本
屏幕适配是可以通过代码实现的,相信给你时间就一定能写出来. 我们公司貌似没有分辨率适配框架通常对应小屏幕的苹果4要额外设置下等等就完了! 屏幕适配框架实现思路: 通过代码获取当前的分辨率 –> ...
- NavMeshAgent 动态加载障碍物
如果你想让游戏人物绕开一些物体, 这些物体动态生成出来的.只需要给物体添加NavMeshObstacle组件即可 1. 绿色方块添加NavMeshObstacle组件 2. 红色方块没有添加NavMe ...
- qt反走样(简选)
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #qt反走样(简选) #概念 """ ...
- bad interpreter: No such file or directory
经常会遇到这种情况,在windows下写的脚本,代码会在linux下无法执行,错误就是: bad interpreter: No such file or directory 1.原因 这通常都是由于 ...
- C#解决MDI窗体闪屏的方法
最近从师兄手上接了一个C#的项目,需要用到MDI窗体,可是每当我显示子窗体的时候会有一次“闪烁”,很明显,看起来非常不爽,查找许久,知道是每次在show()子窗体的时候都会调用子窗体构造函数重绘窗体, ...
- CGRect包含交错,边缘,中心的检测
CGRectContainsPoint函数 判断给定的点是否被一个CGRect包含,可以用CGRectContainsPoint函数 BOOL contains = CGRectCont ...
- ORACLE SEQUENCE用法 (自增长)
在oracle中sequence就是序号,每次取的时候它会自动增加.sequence与表没有关系. 1.Create Sequence 首先要有CREATE SEQUENCE或者CREATE ...
- 指针参数的传递(节选 C++/C 高质量编程 林锐)
指针参数是如何传递内存的 如果函数的参数是一个指针,不要指望用该指针去申请动态内存.示例7-4-1中,Test函数的语句GetMemory(str, 200)并没有使str获得期望的内存,str依旧是 ...
- 查找mysql数据库文件的存放位置
在mysql数据库中,有时候并不是很容易找出mysql数据库文件data的存放位置吗,这时就可以使用mysql自带的命令行工具进行查询. 具体命令如下:show variables like '%da ...