2017浙江省赛 D - Let's Chat ZOJ - 3961
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3961
题目:
ACM (ACMers' Chatting Messenger) is a famous instant messaging software developed by Marjar Technology Company. To attract more users, Edward, the boss of Marjar Company, has recently added a new feature to the software. The new feature can be described as follows:
If two users, A and B, have been sending messages to each other on the last mconsecutive days, the "friendship point" between them will be increased by 1 point.
More formally, if user A sent messages to user B on each day between the (i - m + 1)-th day and the i-th day (both inclusive), and user B also sent messages to user A on each day between the (i - m + 1)-th day and the i-th day (also both inclusive), the "friendship point" between A and B will be increased by 1 at the end of the i-th day.
Given the chatting logs of two users A and B during n consecutive days, what's the number of the friendship points between them at the end of the n-th day (given that the initial friendship point between them is 0)?
Input
There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 10), indicating the number of test cases. For each test case:
The first line contains 4 integers n (1 ≤ n ≤ 109), m (1 ≤ m ≤ n), x and y (1 ≤ x, y ≤ 100). The meanings of n and m are described above, while x indicates the number of chatting logs about the messages sent by A to B, and y indicates the number of chatting logs about the messages sent by B to A.
For the following x lines, the i-th line contains 2 integers la, i and ra, i (1 ≤ la,i ≤ ra, i ≤ n), indicating that A sent messages to B on each day between the la, i-th day and the ra, i-th day (both inclusive).
For the following y lines, the i-th line contains 2 integers lb, i and rb, i (1 ≤ lb,i ≤ rb, i ≤ n), indicating that B sent messages to A on each day between the lb, i-th day and the rb, i-th day (both inclusive).
It is guaranteed that for all 1 ≤ i < x, ra, i + 1 < la, i + 1 and for all 1 ≤ i < y, rb, i + 1 < lb, i + 1.
Output
For each test case, output one line containing one integer, indicating the number of friendship points between A and B at the end of the n-th day.
Sample Input
2
10 3 3 2
1 3
5 8
10 10
1 8
10 10
5 3 1 1
1 2
4 5
Sample Output
3
0
Hint
For the first test case, user A and user B send messages to each other on the 1st, 2nd, 3rd, 5th, 6th, 7th, 8th and 10th day. As m = 3, the friendship points between them will be increased by 1 at the end of the 3rd, 7th and 8th day. So the answer is 3.
思路:手速题+4
暴力n^2匹配就好
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
#define ll first
#define rr second
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int n,m,na,nb;
PII ta[K],tb[K]; int main(void)
{
int t;cin>>t;
while(t--)
{
int ans=;
cin>>n>>m>>na>>nb;
for(int i=;i<=na;i++)
scanf("%d%d",&ta[i].ll,&ta[i].rr);
for(int i=;i<=nb;i++)
scanf("%d%d",&tb[i].ll,&tb[i].rr);
for(int i=;i<=na;i++)
{
for(int j=;j<=nb;j++)
if(tb[j].ll>=ta[i].ll && ta[i].rr>=tb[j].ll)
{
int tmp=min(ta[i].rr,tb[j].rr)-tb[j].ll+;
ans+=tmp>=m?tmp-m+:;
}
else if(tb[j].rr>=ta[i].ll && ta[i].rr>=tb[j].rr)
{
int tmp=tb[j].rr-max(ta[i].ll,tb[j].ll)+;
ans+=tmp>=m?tmp-m+:;
}
else if(ta[i].ll>=tb[j].ll && ta[i].rr<=tb[j].rr)
{
int tmp=ta[i].rr-ta[i].ll+;
ans+=tmp>=m?tmp-m+:;
}
}
printf("%d\n",ans);
}
return ;
}
2017浙江省赛 D - Let's Chat ZOJ - 3961的更多相关文章
- 2017浙江省赛 H - Binary Tree Restoring ZOJ - 3965
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3965 题目: iven two depth-first-search ...
- 2017浙江省赛 E - Seven Segment Display ZOJ - 3962
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目: A seven segment display, or ...
- 2017浙江省赛 A - Cooking Competition ZOJ - 3958
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3958 题目: "Miss Kobayashi's Drag ...
- 2017浙江省赛 C - What Kind of Friends Are You? ZOJ - 3960
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3960 题目: Japari Park is a large zoo ...
- 2017浙江省赛 B - Problem Preparation ZOJ - 3959
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3959 题目: It's time to prepare the pr ...
- (2017浙江省赛E)Seven Segment Display
Seven Segment Display Time Limit: 2 Seconds Memory Limit: 65536 KB A seven segment display, or ...
- Let's Chat ZOJ - 3961
ACM (ACMers' Chatting Messenger) is a famous instant messaging software developed by Marjar Technolo ...
- 2017 湖南省赛 K Football Training Camp
2017 湖南省赛 K Football Training Camp 题意: 在一次足球联合训练中一共有\(n\)支队伍相互进行了若干场比赛. 对于每场比赛,赢了的队伍得3分,输了的队伍不得分,如果为 ...
- ZOJ 3879 Capture the Flag 15年浙江省赛K题
每年省赛必有的一道模拟题,描述都是非常的长,题目都是蛮好写的... sigh... 比赛的时候没有写出这道题目 :( 题意:首先输入4个数,n,q,p,c代表有n个队伍,q个服务器,每支队伍的初始分数 ...
随机推荐
- 【openwrt+arduion】案例
http://www.geek-workshop.com/thread-4950-1-1.html http://www.guokr.com/article/319356/ http://www.gu ...
- 关于CentOS系统中,文件权限第11位上是一个点的解读
http://blog.csdn.net/dashuai03091199/article/details/38920833 http://blog.csdn.net/xinlongabc/articl ...
- Boatloader的工作流程
(1)第一节阶段的功能 1.硬件设备的初始化 2.载入u-boot第二阶段的代码到我们的RAM空间 3.设置好栈 4.跳转到第二阶段的代码入口 (2)第二阶段的功能 1.初始化本阶段所使用的硬件设备 ...
- 你真的搞懂ES6模块的导入导出规则了吗
前言 模块作为ES6规范的核心部分之一,在实际项目开发中经常会看到它的身影,那么我们是否真正了解它的相关规则呢,今天就带大家一起了解一下模块的导入导出规则 导入 ES6模块的导入(即import)大致 ...
- 控制iOS 7中的状态栏
本文转载至:http://blog.csdn.net/pucker/article/details/12112105 苹果终于发布了iOS 7正式版,大批的用户都已经纷纷进行了升级.如果App是由Xc ...
- kafka基础概念
kafka介绍 kafka is a distributed, partitiononed,replicated commited logservice. kafka是一个分布式的.易扩展的.安全性高 ...
- LeetCode 笔记系列三 3Sum
题目:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all ...
- WebStorm 常用安装,配置,快捷键
WebStorm 软件资源 http://pan.baidu.com/s/1c2OmyQW(不建议使用汉化版,都已可能出现很多意想不到的问题) * Web前端集成开发工具 - WebStorm ...
- Big Data资料汇总
整理和翻新一下自己看过和笔记过的Big Data相关的论文和Blog Streaming & Spark In-Stream Big Data Processing Discretized S ...
- 解决mysql不能通过'/tmp/mysql.sock 连接的问题
解决方法:php标准配置正是通过'/tmp/mysql.sock',但一些mysql安装方法将mysql.sock放在/var/lib/mysql.sock或者其他地方,你可以通过修改/etc/my. ...