2013 Multi-University Training Contest 10
HDU-4698 Counting
题意:给定一个二维平面,其中x取值为1-N,y取值为1-M,现给定K个点,问至少包括K个点中的一个的满足要求的<Xmin, Xmax, Ymin, Ymax>共有多少中取值情况。也就是说K个点中至少一个点落在所给定的区间内。
解法:正面求解,由于点只有1000个,因此直接暴力离散化之后的x轴坐标,对于y轴则可以通过增加一个一个加入点,使用一个set来维护纵轴有多少种不同的取法。
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std; typedef long long LL;
const int N = ;
const int mod = int(1e9)+;
const int inf = 0x7fffffff;
struct Point {
int x, y;
Point() {}
Point(int _x, int _y) : x(_x), y(_y) {}
bool operator < (const Point &t) const {
if (x != t.x) return x < t.x;
else return y < t.y;
}
}p[N];
int n, m, K;
int val[N];
set<int>st;
set<int>::iterator it1, it2; int main() {
while (scanf("%d %d %d", &n, &m, &K) != EOF) {
for (int i = ; i <= K; ++i) {
scanf("%d %d", &p[i].x, &p[i].y);
val[i] = p[i].x;
}
sort(p+, p+K+);
sort(val+, val++K);
int cnt = unique(val, val+K+)-val; // 去重之后的x轴坐标
val[] = ; val[cnt++] = n+;
LL ret = ;
for (int i = ; i < cnt-; ++i) {
st.clear(); st.insert(); st.insert(m+);
LL sum = ;
for (int j = i; j < cnt-; ++j) {
int left = lower_bound(p+, p++K, Point(val[j], ))-p;
int right = upper_bound(p+, p++K, Point(val[j], inf))-p;
for (int k = left; k < right; ++k) { // x轴取值为val[j]的点一次性取出来
if (st.count(p[k].y)) continue;
st.insert(p[k].y);
it1 = it2 = st.find(p[k].y);
it1--, it2++; // 找前一个和后一个
sum = (sum+1LL*(p[k].y-*(it1))*(*(it2)-p[k].y)%mod)%mod; // 新增加的y值对,统计只跨过该点的
}
ret = (ret+sum*(val[i]-val[i-])%mod*(val[j+]-val[j])%mod)%mod
}
}
printf("%I64d\n", ret);
}
return ;
}
2013 Multi-University Training Contest 10的更多相关文章
- 2016 Multi-University Training Contest 10
solved 7/11 2016 Multi-University Training Contest 10 题解链接 分类讨论 1001 Median(BH) 题意: 有长度为n排好序的序列,给两段子 ...
- hdu 5416 CRB and Tree(2015 Multi-University Training Contest 10)
CRB and Tree Time Limit: 8000/4000 MS (J ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- [二分,multiset] 2019 Multi-University Training Contest 10 Welcome Party
Welcome Party Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)T ...
- 2015 Multi-University Training Contest 10(9/11)
2015 Multi-University Training Contest 10 5406 CRB and Apple 1.排序之后费用流 spfa用stack才能过 //#pragma GCC o ...
- hdu4705 Y 2013 Multi-University Training Contest 10
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submis ...
- hdu4704 Sum 2013 Multi-University Training Contest 10 数论题
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...
- 2016 Multi-University Training Contest 10 || hdu 5860 Death Sequence(递推+单线约瑟夫问题)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 题目大意:给你n个人排成一列编号,每次杀第一个人第i×k+1个人一直杀到没的杀.然后 ...
随机推荐
- UserSelector兼容
1.更新到asp.net2.0或以上,将Microsoft.Web.UI.TreeView更换为新的System.Web.UI.WebControls.TreeView 2.将UserId,UserT ...
- HDU 3887:Counting Offspring(DFS序+树状数组)
http://acm.hdu.edu.cn/showproblem.php?pid=3887 题意:给出一个有根树,问对于每一个节点它的子树中有多少个节点的值是小于它的. 思路:这题和那道苹果树是一样 ...
- ecshop搜索出现相关商品的效果滑动下拉效果
ecshop搜索栏效果如下 所需要的样式我们可以复制到style.css里: /*搜索滑动效果*/ .Menu { position:absolute; top:30px; left:7px; wid ...
- http://www.bejson.com/go.html?u=http://www.bejson.com/demo2.html
json 解析工具http://www.bejson.com/go.html?u=http://www.bejson.com/demo2.html
- java.lang.IllegalThreadStateException
java.lang.IllegalThreadStateException 今天遇到了这个问题.当时的情景是想要循环实现了runable的类和继承Thread类的两个线程.可是没有注意到,继承自Thr ...
- C# 单例模式Lazy<T>实现版本
非Lazy版本的普通单例实现: public sealed class SingletonClass : ISingleton { private SingletonClass () { // the ...
- JAVA基础知识之网络编程——-网络基础(Java的http get和post请求,多线程下载)
本文主要介绍java.net下为网络编程提供的一些基础包,InetAddress代表一个IP协议对象,可以用来获取IP地址,Host name之类的信息.URL和URLConnect可以用来访问web ...
- SecureCRT issue "Could not open clipboard: Assess is denied" (无法打开粘贴板:访问被拒绝)
I got an issue when copying some line/word (actually just select the context ) in the Linux terminal ...
- HDU(2255),KM算法,最大权匹配
题目链接 奔小康赚大钱 Time Limit: 1000/1000MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- Poj(1273),最大流,EK
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 69355 Accepted: 2687 ...