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 ...
随机推荐
- muduo网络库学习笔记(三)TimerQueue定时器队列
目录 muduo网络库学习笔记(三)TimerQueue定时器队列 Linux中的时间函数 timerfd简单使用介绍 timerfd示例 muduo中对timerfd的封装 TimerQueue的结 ...
- Android 公共库的建立方法
本文主要介绍在android工程中如何将共用代码建成公共包方便其他工程引用.引用后的工程结构分析.library引入方式的优缺点. 自己也写了一些android公共的库,有兴趣的可以参考 Trinea ...
- PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)
如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...
- 对《OA云》作品的分析
对<OA云>作品的分析 软件描述:<OA云>是一款基于移动端的企业日常事物办公软件,企业人员进入该产品后可以对当天的出勤情况进行签到,系统会自动的识别以及记录下员工的实时签到信 ...
- 软工实践周六实践课安排(2017秋学期) | K 班
软工实践周六实践课安排(2017秋学期) | K 班 周数 截止时间 工作内容 阶段成果展示形式 验收方式 备注 4之前 2017.10月前 组队 随笔(提供组队名单.组队队员的介绍--包括擅长的地方 ...
- 0302-对IT行业的感思
在参考并分析了2014行业排名和IT行业的就业分析后,给我的第一体会就是:如今的IT行业,是一个机会与挑战并存的行业. 先说机会. 从行业排行相关资料不难看出,现在是一个信息与大数据引领一切的时代,电 ...
- C#程序解读
阅读下面程序,请回答如下问题: 问题1:这个程序要找的是符合什么条件的数? 问题2:这样的数存在么?符合这一条件的最小的数是什么? 问题3:在电脑上运行这一程序,你估计多长时间才能输出第一个结果?时间 ...
- ejabberd在windows10上安装记录
安装完ejabberd:ejabberd-17.11-windows-installer.exe 启动报错:bash ejabberdctl register "admin" &q ...
- formidable模块的使用
Node.js的Formidable模块的使用 今天总结了下Node.js的Formidable模块的使用,下面做一些简要的说明. 1) 创建Formidable.IncomingForm ...
- 点分治&动态点分治小结
(写篇博客证明自己还活着×2) 转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/8006488.html 有的时候,我们会发现这样一类题:它长得很像一个$O(n) ...