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 ...
随机推荐
- 关于representation的理解
目前见过的定义的比较确切的是Yoshua Bengio在ACL2010的一篇paper中关于word representation的定义: " A word Representation i ...
- 编译Hadoop
Apache Hadoop 生态圈软件下载地址:http://archive.apache.org/dist/hadoop/hadoop下载地址 http://archive.apache.org/d ...
- liunx打开指定端口
1.切换为root用户 2.切换路径至:/etc/sysconfig 3.vi编辑添加一行: -A INPUT -m state --state NEW -m tcp -p tcp --dport 3 ...
- CSS自动换行
style="word-break:break-all;word-wrap:break-word;"
- dddddd
(function(window){ var com = function(box){ this.box = document.querySelector(box); } window.zhangle ...
- Linux系统编程重要细节记录(持续更新中)
1.在打印rlim_t值时,需要将其转换为long long并使用%lld printf()修饰符.
- c#输出、输入
//输出 Console.WriteLine("这是一行文字"); 自动回车的. Console.Write("Hello world"); 不带回车的. ...
- jQuery操作Table tr td常用的方法
虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...
- android6.0锁屏界面接收新通知处理流程
灭屏状态下,接收新信息,屏幕会半亮显示通知流程: 1,应用构造notification后,传给NotificationManager,而后进入NotificationManagerService处理. ...
- module.export和export
module.exports 和 exports 是引用到的同一个对象,类似下面代码所示(为了举例,不是完全的正确): var module.exports = {}; var expo ...