http://www.cnblogs.com/kane0526/archive/2013/03/07/2948446.html

http://blog.csdn.net/acdreamers/article/details/11854781

每块蔬菜地种植蔬菜收获的利润为 val=x*y*price。  面积乘以价格,题目的重点转换在于如何确定重叠区域怎么让它种植最贵的蔬菜。

观察利润计算公式 :   x*y*price <==> x*y*h    可以转换为求体积并。

体积并其实和面积并基本一样,将体积的范围记录下来,每一层遍历求面积并,结果就是底面积乘每一层的高之和

  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <stack>
  9. #include <queue>
  10. #include <cctype>
  11. #include <vector>
  12. #include <iterator>
  13. #include <set>
  14. #include <map>
  15. #include <sstream>
  16. using namespace std;
  17.  
  18. #define mem(a,b) memset(a,b,sizeof(a))
  19. #define pf printf
  20. #define sf scanf
  21. #define spf sprintf
  22. #define pb push_back
  23. #define debug printf("!\n")
  24. #define MAXN 160000+5
  25. #define MAX(a,b) a>b?a:b
  26. #define blank pf("\n")
  27. #define LL long long
  28. #define ALL(x) x.begin(),x.end()
  29. #define INS(x) inserter(x,x.begin())
  30. #define pqueue priority_queue
  31. #define INF 0x3f3f3f3f
  32.  
  33. #define ls (rt<<1)
  34. #define rs (rt<<1|1)
  35.  
  36. int n,m;
  37.  
  38. double hh[MAXN],col[MAXN<<],len[MAXN<<];
  39.  
  40. int V[MAXN];
  41.  
  42. struct node
  43. {
  44. double l,r,x,c;
  45. int v;
  46. node(){}
  47. node(double a,double b,double c,double d,int e):l(a),r(b),x(c),c(d),v(e){}
  48. bool operator < (const node &b) const
  49. {
  50. return x<b.x;
  51. }
  52. }a[MAXN<<],tmp[MAXN<<];
  53.  
  54. void PushUp(int rt,int l,int r)
  55. {
  56. if(col[rt])
  57. {
  58. len[rt] = hh[r+] - hh[l];
  59. }
  60. else if(l==r) len[rt] = ;
  61. else
  62. {
  63. len[rt] = len[ls]+len[rs];
  64. }
  65. }
  66.  
  67. void update(int val,int L,int R,int l,int r,int rt)
  68. {
  69. if(L<=l && r<=R)
  70. {
  71. col[rt] += val;
  72. PushUp(rt,l,r);
  73. return;
  74. }
  75. int mid = (l+r)>>;
  76. if(L <= mid) update(val,L,R,l,mid,ls);
  77. if(R > mid) update(val,L,R,mid+,r,rs);
  78. PushUp(rt,l,r);
  79. }
  80.  
  81. int main()
  82. {
  83. int n,i,j,t,kase=;
  84. double ans;
  85. sf("%d",&t);
  86. while(t--)
  87. {
  88. sf("%d%d",&n,&m);
  89. int v=;
  90. for(i=;i<=m;i++)
  91. sf("%d",&V[i]);
  92. for(i=;i<=n;i++)
  93. {
  94. double x1,x2,y1,y2;
  95. int r;
  96. sf("%lf%lf%lf%lf%d",&x1,&y1,&x2,&y2,&r);
  97. hh[++v]=y1;
  98. a[v]=node(y1,y2,x1,,V[r]);
  99. hh[++v]=y2;
  100. a[v]=node(y1,y2,x2,-,V[r]);
  101. }
  102. sort(hh+,hh++v);
  103. sort(a+,a++v);
  104. int d=;
  105. for(i=;i<=v;i++)
  106. if(hh[i]!=hh[i-])
  107. hh[++d]=hh[i];
  108. double ans=;
  109. V[]=;
  110. sort(V,V+m+);
  111. int ct =;
  112. for(j=;j<=m;j++)
  113. {
  114. ct=;
  115. for(i=;i<=v;i++)
  116. if(a[i].v>V[j-])
  117. tmp[ct++]=a[i];
  118. mem(col,);
  119. mem(len,);
  120. for(i=;i<ct-;i++)
  121. {
  122. //int l=BinarySearch(tmp[i].l,1,M);
  123. //int r=BinarySearch(tmp[i].r,1,M)-1;
  124. int l = lower_bound(hh+,hh+d,tmp[i].l)-hh;
  125. int r = lower_bound(hh+,hh+d,tmp[i].r)-hh-;
  126. if(l<=r) update(tmp[i].c,l,r,,d,);
  127. ans+=len[]*(double)(V[j]-V[j-])*(tmp[i+].x-tmp[i].x);
  128. }
  129. }
  130. pf("Case %d: %.0lf\n",kase++,ans);
  131. }
  132. return ;
  133. }

hdu 3255 体积并的更多相关文章

  1. hdu 3255 Farming(扫描线)

    题目链接:hdu 3255 Farming 题目大意:给定N个矩形,M个植物,然后给定每一个植物的权值pi,pi表示种植物i的土地,单位面积能够收获pi,每一个矩形给定左下角和右上角点的坐标,以及s, ...

  2. HDU 3255 扫描线(立方体体积并变形)

    Farming Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  3. HDU 3255 Farming (线段树+扫面线,求体积并)

    题意:在一块地上种蔬菜,每种蔬菜有个价值.对于同一块地蔬菜价值高的一定是最后存活,求最后的蔬菜总值. 思路:将蔬菜的价值看做高度的话,题目就转化成求体积并,这样就容易了. 与HDU 3642 Get ...

  4. HDU 3255 Farming

    矩形面积并变形,一层一层的算体积 #include<cstdio> #include<cstring> #include<cmath> #include<ma ...

  5. hdu 3642 体积并

    题意:求三个矩形体积的并 链接:点我 枚举z #include<stdio.h> #include<iostream> #include<stdlib.h> #in ...

  6. HDU 2002 计算球体积

    题目链接:HDU 2002 Description 根据输入的半径值,计算球的体积. Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径. Output 输出对应的球的体积,对于每 ...

  7. HDU 1411--校庆神秘建筑(欧拉四面体体积计算)

    校庆神秘建筑 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  8. HDU 3642 扫描线(立方体体积并)

    Get The Treasury Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  9. Get The Treasury HDU - 3642(体积扫描线)

    给出n个立方体,要你求这些立方体至少被覆盖三次的部分. 先把这个立方体的信息存在来,发现Z的范围不大,z范围是是[-500,500],所以我们可以先离散化,然后枚举Z, 然后对于每一段Z的区域内,在当 ...

随机推荐

  1. 【python】Python的logging模块封装

    #!/usr/local/python/bin # coding=utf-8 '''Implements a simple log library. This module is a simple e ...

  2. CPU 的工作原理

    内部架构 CPU 的根本任务就是执行指令,对计算机来说最终都是一串由 0 和 1 组成的序列.CPU 从逻辑上可以划分成 3 个模块,分别是控制单元.运算单元和存储单元 .其内部架构如下: [1]控制 ...

  3. Java面向对象之继承extends 入门实例

    一.基础概念 (一)继承的好处: 1.继承:提高了代码的复用性. 2.让类与类之间产生了关系,给多态这个特征提供了前提. (二)继承的种类: 1.单继承:一个类只能有一个父类. 2.多继承:一个类可以 ...

  4. linux下 zip解压 tar解压 gz解压 bz2等各种解压文件命令

    .tar 解包:tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) ——————————————— .gz 解压 ...

  5. bzoj 3895: 取石子

    $ \color{#0066ff}{ 题目描述 }$ Alice和Bob两个好朋含友又开始玩取石子了.游戏开始时,有N堆石子 排成一排,然后他们轮流操作(Alice先手),每次操作时从下面的规则中任选 ...

  6. 最大子树和 树形dp

    题目描述 小明对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题.一天他早晨骑车去上课,路上见到一个老伯正在修剪花花草草,顿时想到了一个有关修剪花卉的问题.于是当日课后,小明 ...

  7. 简单了解树形DP

    今天在B站看了一个树形DP教学视频有所收获,做一个小小的总结 AV号和链接在这:av12194537 那么先介绍一下树形DP 树形DP就是在树这个特殊的数据结构上进行的DP.有两种方向:自顶向下和自底 ...

  8. HDU - 5050 (大数二进制gcd)

    It's time to fight the local despots and redistribute the land. There is a rectangular piece of land ...

  9. 洛谷P2709 小B的询问

    题目描述 小B有一个序列,包含N个1~K之间的整数.他一共有M个询问,每个询问给定一个区间[L..R],求Sigma(c(i)^2)的值,其中i的值从1到K,其中c(i)表示数字i在[L..R]中的重 ...

  10. Codeforces - 38G 可持久化Treap 区间操作

    题意:\(n\)个人排队,每个人有重要度\(p\)和不要脸度\(c\),如果第\(i\)个人的重要度大于第\(i-1\)个人的重要度,那么他们之间可以交换,不要脸度-1,交换后先前的第\(i\)个人也 ...