转:题意:给定一个二维平面,其中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(思路)的更多相关文章

  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. unity3d笔记:控制特效的播放速度

           一般在游戏中,主角或者怪物会受到减速效果,或者攻击速度减慢等类似的状态.本身动作减速的同时,衔接在角色上的特效也需要改变相应的播放速度.一般特效有三个游戏组件:   关键点就是改变Ani ...

  2. 使用 Sandcastle 生成代码帮助文档

    使用 Sandcastle可以生成MSDN风格的帮助文档,生成的帮助文档既可以是chm文档,也可以是MS Help 2.x帮助文档. 1 下载并安装Sandcastle Sandcastle下载地址为 ...

  3. spring boot分布式技术,spring cloud,负载均衡,配置管理器

    spring boot分布式的实现,使用spring cloud技术. 下边是我理解的spring cloud的核心技术: 1.配置服务器 2.注册发现服务器eureka(spring boot默认使 ...

  4. android命令抓LOG

    手机和电脑,在电脑上开3个命令窗口,分别输入如下3个命令分别抓取mainLog.radioLog和kernalLog adb logcat -v time >main.txt adb logca ...

  5. python day2 列表的常用操作方法

    #创建列表方法一li = ['aa','bb','cc']方法二li = list(['aa','bb','cc'])print(li)返回 ['aa', 'bb', 'cc']----------- ...

  6. js复制内容加版权声明代码

    $("body").on('copy', function (e) { if (typeof window.getSelection == "undefined" ...

  7. 判断是否是有效的IPV4地址

    参考链接: https://blogs.msdn.microsoft.com/oldnewthing/20060522-08/?p=31113 http://www.cnblogs.com/txw19 ...

  8. 易学PHP——WAMP环境搭建

    安装前的准备 查看本机的类型(x86/x64,即 32 位还是 64 位) 安装好 VC9/VC11/VC14 运行库(需要按照本机的类型选择安装) 创建好一个安装路径用于安装整套 amp 环境(我使 ...

  9. JavaScript-navigator_userAgent-编写一段代码能够区分浏览器的主流和区分

    1 userAgent:包含浏览器名称和版本号的字符串 <!DOCTYPE html> <html> <head lang="en"> < ...

  10. tomcat 假死现象(转)

    1.1 编写目的 为了方便大家以后发现进程假死的时候能够正常的分析并且第一时间保留现场快照. 1.2编写背景 最近服务器发现tomcat的应用会偶尔出现无法访问的情况.经过一段时间的观察最近又发现有台 ...