CF 1131B Draw!
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
You still have partial information about the score during the historic football match. You are given a set of pairs (ai,bi)(ai,bi), indicating that at some point during the match the score was "aiai: bibi". It is known that if the current score is «xx:yy», then after the goal it will change to "x+1x+1:yy" or "xx:y+1y+1". What is the largest number of times a draw could appear on the scoreboard?
The pairs "aiai:bibi" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.
Input
The first line contains a single integer nn (1≤n≤100001≤n≤10000) — the number of known moments in the match.
Each of the next nn lines contains integers aiai and bibi (0≤ai,bi≤1090≤ai,bi≤109), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).
All moments are given in chronological order, that is, sequences xixi and yjyj are non-decreasing. The last score denotes the final result of the match.
Output
Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.
Sample Input
3
2 0
3 1
3 4
2
3
0 0
0 0
0 0
1
1
5 4
5
Hint
In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.
题意:
两个人进行比赛,给出几场两人的比分,问在满足这几场比分的条件下,最多会出现几场平局(开始的0:0也算一场)。
解题思路:
将比赛双方看成两条不断前进的线段,利用区间的方式去模拟比赛的情况。
重点是Debug,在思路找不到错误的情况下,就去多试一些样例,尽量的做到测试的不重不漏。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp();
const int N = ; queue<LL> check;
int main()
{
LL i,p,j,n,t;
LL ans = ;
LL a1,b1,a2,b2; while(!check.empty())
check.pop(); scanf("%lld",&n);
scanf("%lld%lld",&a1,&b1); ans += min(a1, b1) + ;
check.push(min(a1,b1));
for(i = ; i < n; i ++)
{
scanf("%lld%lld",&a2,&b2);
if(a2 < b1 || a1 > b2)
;
else if(a1 < b1 && a2 <= b2 && a2 >= b1)
{
ans+=(a2 - b1) + ; if(check.front() == b1)
{
ans--; }
check.pop();
check.push(a2);
}
else if(a1 >= b1 && a2 <= b2)
{
ans+=(a2 - a1 + ); if(check.front() == a1)
{
ans--; }
check.pop();
check.push(a2);
}
else if(a1 >= b1 && a1 <= b2 && a2 > b2)
{
ans += b2 - a1 + ; if(check.front() == a1)
{
ans--; }
check.pop();
check.push(b2);
}
else if(a1 <= b1 && a2 >= b2)
{
ans += b2 - b1 + ; if(check.front() == b1)
{
ans--; }
check.pop();
check.push(b2);
}
a1 = a2;
b1 = b2;
}
printf("%lld\n",ans);
return ;
}
CF 1131B Draw!的更多相关文章
- CF 1131A,1131B,1131C,1131D,1131F(Round541 A,B,C,D,F)题解
A. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CF 553A 组合DP
http://codeforces.com/problemset/problem/553/A A. Kyoya and Colored Balls time limit per test 2 seco ...
- 【打CF,学算法——三星级】Codeforces Round #313 (Div. 2) C. Gerald's Hexagon
[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/C 题面: C. Gerald's Hexagon time limit per tes ...
- CF泛做
CF Rd478 Div2 A Aramic script 题意:给定几个字符串,去重后,求种类 思路:直接map乱搞 #include<bits/stdc++.h> using name ...
- 【codeforces】【比赛题解】#937 CF Round #467 (Div. 2)
没有参加,但是之后几天打了哦,第三场AK的CF比赛. CF大扫荡计划正在稳步进行. [A]Olympiad 题意: 给\(n\)个人颁奖,要满足: 至少有一个人拿奖. 如果得分为\(x\)的有奖,那么 ...
- CF练习记录
2018/5/6 Codeforces Round #478 (Div. 2) C http://codeforces.com/contest/975/problem/C Valhalla Siege ...
- 深入浅出聊优化:从Draw Calls到GC
前言: 刚开始写这篇文章的时候选了一个很土的题目...<Unity3D优化全解析>.因为这是一篇临时起意才写的文章,而且陈述的都是既有的事实,因而给自己“文(dou)学(bi)”加工留下的 ...
- Direct3D Draw函数 异步调用原理解析
概述 在D3D10中,一个基本的渲染流程可分为以下步骤: 清理帧缓存: 执行若干次的绘制: 通过Device API创建所需Buffer: 通过Map/Unmap填充数据到Buffer中: 将Buff ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
随机推荐
- ABP中文文档及源码说明
目录 ABP.ModuleZero(ABP自带的一套用户模块) 版本管理(Edition) 特性管理(Feature)
- CoreDNS Plugins ---> hosts
需求 kubernetes集群外部有少量服务,kubernetes集群内部pod需要通过服务所在的主机的hostname访问服务. 解决方案 通过coredns的hosts插件配置kubernetes ...
- 数据库——SQL数据连接查询
连接查询 查询结果或条件涉及多个表的查询称为连接查询SQL中连接查询的主要类型 广义笛卡尔积 等值连接(含自然连接) 自身连接查询 外连接查询 一.广义笛卡尔积 不带连 ...
- C语言版本:单链表的实现(优化版本)
未优化版本:http://www.cnblogs.com/duwenxing/p/7569376.html slist.h #ifndef __SLIST_H__ #define __SLIST_H_ ...
- [转帖] sparkdev 的 博客 systemd
从 init 系统说起 https://www.cnblogs.com/sparkdev/p/8448237.html systemd的内容 需要学习下. linux 操作系统的启动首先从 BIOS ...
- 如何设置Listbox的行间距?
关于Listbox的问题? 1. 如何设置Listbox的行间距? 2. 如何实现当鼠标点击Listbox时,被选中的那一行在鼠标点击处出现一控件? 也就是怎么计算出被选中的那一行鼠标点击处的 ...
- mybatis之一对一关联
MapperAsso.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper ...
- css后代选择器 .属性 元素 与 元素.属性的区别
经常看见css的后代选择器是这样的写法: div.class 和 .class div 的形式两者的区别: div.class 是选中的类名为class 的div元素,与直接使用类选择器.cla ...
- MT【171】共轭相随
$\textbf{证明:}$对任意$a,b\in R^+$, $\dfrac{1}{\sqrt{a+2b}}+\dfrac{1}{\sqrt{a+4b}}+\dfrac{1}{\sqrt{a+6b}} ...
- 【刷题】BZOJ 4945 [Noi2017]游戏
Description http://www.lydsy.com/JudgeOnline/upload/Noi2017D2.pdf Solution 字符串里的'x'看起来很烦,于是考虑枚举这些'x' ...