转:题意:给定一个二维平面,其中x取值为1-N,y取值为1-M,现给定K个点,问至少包括K个点中的一个的满足要求的<Xmin, Xmax, Ymin, Ymax>共有多少中取值情况。也就是说K个点中至少一个点落在所给定的区间内。

解法:正面求解,由于点只有1000个,因此直接暴力离散化之后的x轴坐标,对于y轴则可以通过增加一个一个加入点,使用一个set来维护纵轴有多少种不同的取法。

代码如下;

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <stack>
  8. #include <queue>
  9. #include <set>
  10.  
  11. #define LL long long
  12. #define mod 1000000007
  13. #define M 1005
  14. #define INF 0x7fffffff
  15.  
  16. using namespace std;
  17.  
  18. struct Point
  19. {
  20. int x, y;
  21. bool operator < (const Point &temp) const
  22. {
  23. if(x!=temp.x) return x<temp.x;
  24. else return y<temp.y;
  25. }
  26. int readPoint()
  27. {
  28. return scanf("%d%d", &x, &y);
  29. }
  30. } p[M];
  31. int n, m, k;
  32. int val[M];
  33. set<int>sset;
  34. set<int>::iterator it;
  35. int main ()
  36. {
  37. while(~scanf("%d%d%d", &n, &m, &k))
  38. {
  39. for(int i = 1; i <= k; ++i)
  40. {
  41. p[i].readPoint();
  42. val[i] = p[i].x;
  43. }
  44. sort(p+1, p+1+k);
  45. sort(val+1, val+1+k);
  46. int tot = unique(val+1, val+1+k) - val;
  47. val[0] = 0;
  48. val[tot] = n+1;
  49. LL ans = 0;
  50. for(int i = 1; i < tot; ++i)
  51. {
  52. LL tt = 0;
  53. int pre = val[i]-val[i-1];
  54. int r;
  55. for(r = 1; r <= k && p[r].x < val[i]; ++r);
  56. sset.clear();
  57. sset.insert(0);
  58. sset.insert(m+1);
  59. for(int j = i; j < tot; ++j)
  60. {
  61. int top, bottom;
  62. for( ; r <= k && p[r].x == val[j]; ++r)
  63. {
  64. if(sset.count(p[r].y)) continue;
  65. it = sset.lower_bound(p[r].y);
  66. top = *it;
  67. bottom = *(--it);
  68. tt = (tt+(LL)(top-p[r].y)*(p[r].y-bottom)%mod)%mod;
  69. sset.insert(p[r].y);
  70. }
  71. int rear = val[j+1]-val[j];
  72. ans = (ans+tt*rear%mod*pre%mod)%mod;
  73. }
  74. }
  75. printf("%I64d\n", ans);
  76. }
  77. return 0;
  78. }

hdu 4698 - Counting(思路)的更多相关文章

  1. [hdu 6184 Counting Stars(三元环计数)

    hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...

  2. hdu 5862 Counting Intersections

    传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...

  3. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  4. Hdu 5862 Counting Intersections(有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点+树状数组区间求和单点跟新)

    传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的 ...

  5. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  6. HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)

    版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...

  7. HDU 1264 Counting Squares(线段树求面积的并)

    Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. hdu 3887 Counting Offspring dfs序+树状数组

    Counting Offspring Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  9. HDU 5862 Counting Intersections (树状数组)

    Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...

随机推荐

  1. Android 手机自动化测试工具有哪几种?

    1.Monkey是Android SDK自带的测试工具,在测试过程中会向系统发送伪随机的用户事件流,如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进行压力测试,也有日志输出.实际上该工 ...

  2. js闭包使用

    闭包就是在一个函数内定义一个内部函数 并返回内部函数 function f1(){ var a=1; add=function(){a=a+1;} function f1Sub(){ console. ...

  3. 分享Db4o的便捷封装类源码

    导言 大家好,话说真是好久好久没写文章了,哈哈. 最近在写网站,个人对传统数据库天然抵触,感觉非常繁冗,即便是Entity Framework也过于庞杂了,Db4o这种轻量级且读写.配置都极其方便的新 ...

  4. Mysql插入数据为何要加上" ` "(Esc下面那个按键符号)?

    资料上和以前学习的SQL语言,往数据库里面插入数据语句是这样的 INSERT INTO test_table (clo_1, col_2) VALUES("this is value of ...

  5. myql数据库在cmd下,中文乱码的问题原因

    使用navicat把数据导入数据库,这些数据都是中文,导入成功,显式也正常,但是在mysql cmd下都是乱码.检查了我的mysql配置,字符编码都是utf8,包括navicat连接时候也设置过是ut ...

  6. varnish

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

  7. LINUX 如何开放端口和关闭端口/jps/sudo命令

    1 在java的根目录下用java的jps查看:============================================================================ ...

  8. vs

    https://www.visualstudio.com/downloads/download-visual-studio-vs

  9. mysql:添加索引

    ALTER TABLE tb_user_type ADD INDEX user_type_index3 (report_type_id) ALTER TABLE tb_user_type ADD IN ...

  10. archlinux 安装过程记录

    2014年安装了一次,使用U盘启动安装的,但是当时网络有问题,断断续续,没有做详细记录. 现在到了杭州,重新来一次. 使用U盘安装 下载ISO :http://mirrors.163.com/arch ...