HDU 3255 扫描线(立方体体积并变形)
Farming
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1375 Accepted Submission(s): 402
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 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.
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <cmath>
- #include <set>
- using namespace std;
- #define N 30005
- #define ll root<<1
- #define rr root<<1|1
- #define mid (a[root].l+a[root].r)/2
- int max(int x,int y){return x>y?x:y;}
- int min(int x,int y){return x<y?x:y;}
- int abs(int x,int y){return x<?-x:x;}
- struct node{
- int l, r, val, sum;
- }a[N*];
- struct Line{
- int x1, x2, y, val;
- Line(){}
- Line(int a,int b,int c,int d){
- x1=a;
- x2=b;
- y=c;
- val=d;
- }
- }line[N*];
- bool cmp(Line a,Line b){
- return a.y<b.y;
- }
- struct Cube{
- int x1, y1, z1, x2, y2, z2;
- }cu[N];
- int n, m;
- int p[];
- int xx[N*];
- int zz[N*];
- int nx, nz;
- int b_s(int key){
- int l=, r=nx-;
- while(l<=r){
- int mm=(l+r)/;
- if(xx[mm]==key) return mm;
- else if(xx[mm]>key) r=mm-;
- else if(xx[mm]<key) l=mm+;
- }
- }
- void build(int l,int r,int root){
- a[root].l=l;
- a[root].r=r;
- a[root].val=a[root].sum=;
- if(l==r) return;
- build(l,mid,ll);
- build(mid+,r,rr);
- }
- void up(int root){
- if(a[root].val) a[root].sum=xx[a[root].r+]-xx[a[root].l];
- else if(a[root].l==a[root].r) a[root].sum=;
- else a[root].sum=a[ll].sum+a[rr].sum;
- }
- void update(int l,int r,int val,int root){
- if(a[root].l==l&&a[root].r==r){
- a[root].val+=val;
- up(root);
- return;
- }
- if(r<=a[ll].r) update(l,r,val,ll);
- else if(l>=a[rr].l) update(l,r,val,rr);
- else{
- update(l,mid,val,ll);
- update(mid+,r,val,rr);
- }
- up(root);
- }
- main()
- {
- int t, i, j, k;
- int kase=;
- cin>>t;
- while(t--){
- scanf("%d %d",&n,&m);
- for(i=;i<=m;i++) scanf("%d",&p[i]);
- nx=nz=;
- for(i=;i<n;i++){
- scanf("%d %d %d %d %d",&cu[i].x1,&cu[i].y1,&cu[i].x2,&cu[i].y2,&cu[i].z2);
- cu[i].z1=;
- cu[i].z2=p[cu[i].z2];
- xx[nx++]=cu[i].x1;
- xx[nx++]=cu[i].x2;
- zz[nz++]=cu[i].z1;
- zz[nz++]=cu[i].z2;
- }
- sort(xx,xx+nx);
- sort(zz,zz+nz);
- nx=unique(xx,xx+nx)-xx;
- nz=unique(zz,zz+nz)-zz;
- __int64 ans=;
- for(i=;i<nz;i++){
- k=;
- for(j=;j<n;j++){
- if(cu[j].z1<=zz[i-]&&cu[j].z2>=zz[i]){
- line[k++]=Line(cu[j].x1,cu[j].x2,cu[j].y1,);
- line[k++]=Line(cu[j].x1,cu[j].x2,cu[j].y2,-);
- }
- }
- sort(line,line+k,cmp);
- build(,nx,);
- __int64 num=;
- for(j=;j<k-;j++){
- update(b_s(line[j].x1),b_s(line[j].x2)-,line[j].val,);
- num+=(__int64)a[].sum*(__int64)(line[j+].y-line[j].y);
- }
- ans+=num*(__int64)(zz[i]-zz[i-]);
- }
- printf("Case %d: %I64d\n",kase++,ans);
- }
- }
HDU 3255 扫描线(立方体体积并变形)的更多相关文章
- hdu 3255 Farming(扫描线)
题目链接:hdu 3255 Farming 题目大意:给定N个矩形,M个植物,然后给定每一个植物的权值pi,pi表示种植物i的土地,单位面积能够收获pi,每一个矩形给定左下角和右上角点的坐标,以及s, ...
- HDU 3094 树上删边 NIM变形
基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...
- HDU 3642 扫描线(立方体体积并)
Get The Treasury Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 3265 扫描线(矩形面积并变形)
Posters Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu 3255 体积并
http://www.cnblogs.com/kane0526/archive/2013/03/07/2948446.html http://blog.csdn.net/acdreamers/arti ...
- HDU 3255 Farming (线段树+扫面线,求体积并)
题意:在一块地上种蔬菜,每种蔬菜有个价值.对于同一块地蔬菜价值高的一定是最后存活,求最后的蔬菜总值. 思路:将蔬菜的价值看做高度的话,题目就转化成求体积并,这样就容易了. 与HDU 3642 Get ...
- HDU 3255 Farming
矩形面积并变形,一层一层的算体积 #include<cstdio> #include<cstring> #include<cmath> #include<ma ...
- HDU 2002 计算球体积
题目链接:HDU 2002 Description 根据输入的半径值,计算球的体积. Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径. Output 输出对应的球的体积,对于每 ...
- hdu 1542 扫描线求矩形面积的并
很久没做线段树了 求矩形面积的并分析:1.矩形比较多,坐标也很大,所以横坐标需要离散化(纵坐标不需要),熟悉离散化后这个步骤不难,所以这里不详细讲解了,不明白的还请百度2.重点:扫描线法:假想有一条扫 ...
随机推荐
- [转载] linux cgroup
原文: http://coolshell.cn/articles/17049.html 感谢左耳朵耗子的精彩文章. 前面,我们介绍了Linux Namespace,但是Namespace解决的问题主要 ...
- zoj2589Circles(平面图的欧拉定理)
链接 连通图中: 设一个平面图形的顶点数为n,划分区域数为r,一笔画笔数为也就是边数m,则有: n+r-m=2 那么不算外面的那个大区域的话 就可以写为 n+r-m = 1 那么这个题就可以依次求出每 ...
- Broadcast Receviewer
使用Braodcast Receiver 一.新建一个空的工程,命名为LearnBroadcastReceiver 二.为主界面添加一个按钮 三.新建一个broadcast receiver,命名为M ...
- Java后端开发
Java后端开发 名称 内容 基本框架 Spring.Mybatis Linux服务器 数据库优化 消息服务 rabbitMQ.activeMq rocketMq 缓存服务 memcached ...
- PHP中file_put_contents追加和换行
在PHP的一些应用中需要写日志或者记录一些信息,这样的话.可以使用fopen(),fwrite()以及 fclose()这些进行操作.也可以简单的使用file_get_contents()和file_ ...
- 转:C语言中的static变量和C++静态数据成员(static member)
转自:C语言中的static变量和C++静态数据成员(static member) C语言中static的变量:1).static局部变量 a.静态局部变量在函数内定义,生存期为整个程序 ...
- Eclipse中导入外部jar包(zhuan)
http://jingyan.baidu.com/article/ca41422fc76c4a1eae99ed9f.html ************************************* ...
- JS 判断当前使用浏览器名及版本
由于我的后台系统的上传图片不支持IE浏览器的,所以我需要判断公司人员在使用后台系统的时候,是否使用的浏览器是IE的. // 获取当前浏览器名 及 版本号 function appInfo(){ var ...
- Html_页面的高度宽度等
offsetTop 指元素距离上方或上层控件的位置,整型,单位像素. offsetLeft 指元素距离左方或上层控件的位置,整型,单位像素. offsetWidth 指元素控件自身的宽度,整型,单位像 ...
- jquery: 一些常见的获取
jq1.6+ 勾选checked $(#id).attr("checked", true); 判断checkbox是否选择 $(#id).prop("checked&qu ...