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 ...
随机推荐
- PAT甲题题解-1091. Acute Stroke (30)-BFS
题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...
- 【Alpha】功能规格说明书
更新说明:从用户需求分析中剥离有关用户场景分析部分,加入功能规格说明书. Github地址:https://github.com/buaase/Phylab-Web/blob/master/docs/ ...
- linux第十八章学习笔记
第十八章 调试 内核级开发的调试工作远比用户级开发艰难,它带来的风险比用户级别更高. 一.准备开始 1. 准备工作需要: 一个bug 一个藏匿bug的内核版本 相关内核代码的知识和运气 2. 在用户级 ...
- 《Linux内核分析》第一周——计算机是如何工作的?
杨舒雯 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 课程内容 1.诺曼依体系 ...
- 第二个spring冲刺第8天
今天我们团队分别安排了不同的任务,分别是1人程序编写,1人检查bug,1人负责客户体验,还有我们的总负责人王俊凯同学负责各个部分的协调.今天程序有了新的调整,但是功能还是没有完全做出来,不过还在开发途 ...
- .net 开源组件推荐 之 StackExchange
已经两年没更新过博客了!!! StackExchange,地址:https://github.com/StackExchange,开源的这些项目都是在StackOverflow线上使用的. 说起Sta ...
- SparkException: Master removed our application
come from https://stackoverflow.com/questions/32245498/sparkexception-master-removed-our-application ...
- js手写俄罗斯方块
代码如下 html: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...
- Json序列化循环引用的问题
今天在发布接口的时候出突然出现了一个问题,报错代码为: 1 An exception has occurred while using the formatter 'JsonMediaTypeForm ...
- 设置close