hdu 4698 - Counting(思路)
转:题意:给定一个二维平面,其中x取值为1-N,y取值为1-M,现给定K个点,问至少包括K个点中的一个的满足要求的<Xmin, Xmax, Ymin, Ymax>共有多少中取值情况。也就是说K个点中至少一个点落在所给定的区间内。
解法:正面求解,由于点只有1000个,因此直接暴力离散化之后的x轴坐标,对于y轴则可以通过增加一个一个加入点,使用一个set来维护纵轴有多少种不同的取法。
代码如下;
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <cstring>
- #include <algorithm>
- #include <vector>
- #include <stack>
- #include <queue>
- #include <set>
- #define LL long long
- #define mod 1000000007
- #define M 1005
- #define INF 0x7fffffff
- using namespace std;
- struct Point
- {
- int x, y;
- bool operator < (const Point &temp) const
- {
- if(x!=temp.x) return x<temp.x;
- else return y<temp.y;
- }
- int readPoint()
- {
- return scanf("%d%d", &x, &y);
- }
- } p[M];
- int n, m, k;
- int val[M];
- set<int>sset;
- set<int>::iterator it;
- int main ()
- {
- while(~scanf("%d%d%d", &n, &m, &k))
- {
- for(int i = 1; i <= k; ++i)
- {
- p[i].readPoint();
- val[i] = p[i].x;
- }
- sort(p+1, p+1+k);
- sort(val+1, val+1+k);
- int tot = unique(val+1, val+1+k) - val;
- val[0] = 0;
- val[tot] = n+1;
- LL ans = 0;
- for(int i = 1; i < tot; ++i)
- {
- LL tt = 0;
- int pre = val[i]-val[i-1];
- int r;
- for(r = 1; r <= k && p[r].x < val[i]; ++r);
- sset.clear();
- sset.insert(0);
- sset.insert(m+1);
- for(int j = i; j < tot; ++j)
- {
- int top, bottom;
- for( ; r <= k && p[r].x == val[j]; ++r)
- {
- if(sset.count(p[r].y)) continue;
- it = sset.lower_bound(p[r].y);
- top = *it;
- bottom = *(--it);
- tt = (tt+(LL)(top-p[r].y)*(p[r].y-bottom)%mod)%mod;
- sset.insert(p[r].y);
- }
- int rear = val[j+1]-val[j];
- ans = (ans+tt*rear%mod*pre%mod)%mod;
- }
- }
- printf("%I64d\n", ans);
- }
- return 0;
- }
hdu 4698 - Counting(思路)的更多相关文章
- [hdu 6184 Counting Stars(三元环计数)
hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...
- hdu 5862 Counting Intersections
传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- Hdu 5862 Counting Intersections(有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点+树状数组区间求和单点跟新)
传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的 ...
- HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)
版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...
- HDU 1264 Counting Squares(线段树求面积的并)
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 3887 Counting Offspring dfs序+树状数组
Counting Offspring Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 5862 Counting Intersections (树状数组)
Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...
随机推荐
- Android 手机自动化测试工具有哪几种?
1.Monkey是Android SDK自带的测试工具,在测试过程中会向系统发送伪随机的用户事件流,如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进行压力测试,也有日志输出.实际上该工 ...
- js闭包使用
闭包就是在一个函数内定义一个内部函数 并返回内部函数 function f1(){ var a=1; add=function(){a=a+1;} function f1Sub(){ console. ...
- 分享Db4o的便捷封装类源码
导言 大家好,话说真是好久好久没写文章了,哈哈. 最近在写网站,个人对传统数据库天然抵触,感觉非常繁冗,即便是Entity Framework也过于庞杂了,Db4o这种轻量级且读写.配置都极其方便的新 ...
- Mysql插入数据为何要加上" ` "(Esc下面那个按键符号)?
资料上和以前学习的SQL语言,往数据库里面插入数据语句是这样的 INSERT INTO test_table (clo_1, col_2) VALUES("this is value of ...
- myql数据库在cmd下,中文乱码的问题原因
使用navicat把数据导入数据库,这些数据都是中文,导入成功,显式也正常,但是在mysql cmd下都是乱码.检查了我的mysql配置,字符编码都是utf8,包括navicat连接时候也设置过是ut ...
- varnish
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- LINUX 如何开放端口和关闭端口/jps/sudo命令
1 在java的根目录下用java的jps查看:============================================================================ ...
- vs
https://www.visualstudio.com/downloads/download-visual-studio-vs
- mysql:添加索引
ALTER TABLE tb_user_type ADD INDEX user_type_index3 (report_type_id) ALTER TABLE tb_user_type ADD IN ...
- archlinux 安装过程记录
2014年安装了一次,使用U盘启动安装的,但是当时网络有问题,断断续续,没有做详细记录. 现在到了杭州,重新来一次. 使用U盘安装 下载ISO :http://mirrors.163.com/arch ...