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 ...
随机推荐
- ImageUtil(验证码数据生成工具类)
登录界面时,常常会使用到验证码图片生成,程序如下: package util; import java.awt.Color; import java.awt.Font; import java.awt ...
- NGUI BUG /各种坑
以下为:NGUI3.6具体使用过程中碰到的 各种BUG /各种坑 备忘 1.UIToggle 使用UIToggle组件实现多个tab标签互斥,如果是在代码中动态的设置显示某个tab标签对应的内容,则需 ...
- Git查看、删除、重命名远程分支和tag(转)
转:http://zengrong.net/post/1746.htm 这篇文章记录我在使用git的过程中碰到远程分支和tag的相关内容,提纲: 查看远程分支 删除远程分支和tag 删除不存在对应远程 ...
- configparser配置文件操作
configparser 模块用于对配置操作 官方文档地址https://docs.python.org/3/library/configparser.html 导入configparser模块 i ...
- python学习笔记-多进程
multiprocessing from multiprocessing import Process import time def f(name): time.sleep(2) print('he ...
- easyui的getRows和appendRow方法使用结果记录
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- ModelAndView详解
ModelAndView的构造方法有7个.但是它们都是相通的. 这里使用无参构造函数来举例说明如何构造ModelAndView实例. ModelAndView类别就如其名称所示,是代表了MVC Web ...
- ubuntu locale 语言设置
第一步,编辑文件 代码: sudo gedit /var/lib/locales/supported.d/local 写入相关内容,比如写入如下内容: 代码: zh_CN.UTF-8 UTF-8zh ...
- js分秒必争
将函数和对象合写在一起时,函数就变成了“方法”(method): //当函数赋值给对象的属性,我们称之为 //方法.所有的JavaScript的对象都含有方法 var a=[]; //创 ...
- 向NFV过渡 这三个坑我替你趟了
网络功能虚拟化(NFV)在最近几年不断发展,并开始现实商业部署.通信服务商也必须解决自身所面临的挑战,包括安全.性能.投入产出比.与现有网络实现电信级交互.运营支撑系统(OSS)和业务支撑系统(BSS ...