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 ...
随机推荐
- Linux服务器SNMP常用OID (转)
原文地址:http://www.haiyun.me/archives/linux-snmp-oid.html 收集整理一些Linux下snmp常用的OID,用做服务器监控很不错. 服务器负载: 1 2 ...
- WEB打印插件jatoolsPrinter
为什么选择 jatoolsPrinter 免费版? 支持无预览直接打印 真正免费,不加水印,没有ip或域名限制,不限时间,兼容ie6+ 无须注册,下载即用 提供经过微软数字签名的cab自动安装包,安装 ...
- Roman to Integer && Integer to Roman 解答
Roman Numeral Chart V:5 X:10 L:50 C:100 D:500 M:1000 规则: 1. 重复次数表示该数的倍数2. 右加左减:较大的罗马数字右边记上较小的罗马数字,表示 ...
- 关于vs的lib文件和dll文件
一.LIB文件概念 一个lib文件是obj文件的集合.当然,其中还夹杂着其他一些辅助信息,目的是为了让编译器能够准确找到对应的obj文件 二.与DLL的区别 (1)lib是编译时需要的,dll是运行时 ...
- Hive 8、Hive2 beeline 和 Hive jdbc
1.Hive2 beeline Beeline 要与HiveServer2配合使用,支持嵌入模式和远程模式 启动beeline 打开两个Shell窗口,一个启动Hive2 一个beeline连接hi ...
- ps&&/proc/pid/xxx
ps 如果想看一个进程的启动时间,可以用lstart来看 [root@jiangyi02.sqa.zmf /home/ahao.mah] #ps -eo pid,lstart,etime,cmd |g ...
- KafkaOffsetMonitor监控
介绍 KafkaOffsetMonitor是有由Kafka开源社区提供的一款Web管理界面,这个应用程序用来实时监控Kafka服务的Consumer以及它们所在的Partition中的Offset,你 ...
- linux下git使用记录1 git 提交
linux下git使用记录1 浏览:985 发布日期:2013/08/08 分类:技术分享 在使用github的时候,不可避免的接触到了git,用他来更新项目,做版本控制.这里特别把常用的命令记录 ...
- NET基础课--开发工具实用功能
1.浏览代码结构 类视图 2.重构功能 提取长的的方法体中的部分方法到单独函数中 路径:选择代码段,右击重构----提取方法 3.代码结构 a 代码对齐 点[编辑]-[高级]-[设置选定内容的格式] ...
- html进阶css(2)
选择器的类型 <!doctype html> <html> <head> <meta charset="utf-8"> <ti ...