题目链接:http://codeforces.com/problemset/problem/499/A

题目意思:有两种按钮:1、如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解为跳到t+1;  2、直接跳过 x 分钟,如果player在第 t 分钟,则可以跳到 t+x 分钟。问恰好可以看完 n 部电影的最少观看时间。观看一部电影(假如为第 i 部,起始时间为 li, 结束时间为 ri)表示 li, li+1, li+2, ..., ri-1, ri 的时间都要覆盖到。

  一开始做的时候想得太简单了,确实需要将每部电影的所有时间都覆盖到,但是要考虑到,如果不能恰好到达 li 这个时间点的话,意味着要在 li 之前的某个点就要开始覆盖,直到 ri。

  我的做法是用一个cur_mom来记录看下一部电影前的到达时间。初始的时候是 1(题目说的)。问题是如何确定可以恰好到达 li。这里可以通过比较 li - cur_mom 是否能被 x 整除来判断。有余数的话代表不能恰好到达。处理完一部电影之后要更新cur_mom,它等于这部电影的结束时间 +1。

  

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n, x;
while (scanf("%d%d", &n, &x) != EOF)
{
int l, r;
int ans = ;
int cur_mom = ; for (int i = ; i < n; i++)
{
scanf("%d%d", &l, &r);
if ((l-cur_mom) % x)
{
int tmp = l - cur_mom;
int num = tmp / x;
cur_mom += num * x;
}
else
cur_mom = l;
ans += r - cur_mom + ;
cur_mom = r+;
}
printf("%d\n", ans);
}
return ;
}

  

codeforces 499A.Inna and Pink Pony 解题报告的更多相关文章

  1. codeforces 374A Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...

  2. Codeforces 374A - Inna and Pink Pony

    原题地址:http://codeforces.com/contest/374/problem/A 好久没写题目总结了,最近状态十分不好,无论是写程序还是写作业还是精神面貌……NOIP挂了之后总觉得缺乏 ...

  3. 220 DIV2 A. Inna and Pink Pony

    Inna and Pink Pony 输入n,m,i,j,a,b 可以看成n行m列的矩阵,起点(i,j),每次移动(a,b),(-a,-b),(-a,b),(a,-b) 可移动到(1,m),(n,1) ...

  4. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  5. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  6. codeforces B. Eugeny and Play List 解题报告

    题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...

  7. codeforces 433C. Ryouko's Memory Note 解题报告

    题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...

  8. codeforces 556B. Case of Fake Numbers 解题报告

    题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...

  9. codeforces 510B. Fox And Two Dots 解题报告

    题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...

随机推荐

  1. shell学习之路:流程控制(for)

    for循环的语法: 1.  for 变量 in 值1 值2 值3.... do 程序 done 例如:下列脚本会分别打印4次 分别是morning noon afternoon evening的值 # ...

  2. mfc 调试 弹消息

    AfxMessageBox(_T("edit change msg")); OutputDebugString(L"jian "); CString str; ...

  3. 大数据——sparksql

    sparksql:http://www.cnblogs.com/shishanyuan/p/4723604.html?utm_source=tuicool spark on yarn :http:// ...

  4. Codeforces Round #202 (Div. 2) A,B

    A. Cinema Line time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  5. C#之正则表达式、异常处理和委托与事件

    正则表达式主要是为了处理和模式匹配复杂的字符串. int myInteger = 5; string intergerString = myInteger.ToString(); 就是将myInteg ...

  6. linux之vim编辑神器

    设置编辑器:export EDITOR=vim 1.ctrl+x ctrl+e  创建vim临时文件 2.ctrl+[ 退回到命令模式 3.命令模式下ZZ,保存退出 4.大写I行首插入,大写A行尾插入 ...

  7. 虚拟机安装Ubuntu三种网络模式

    VMWare提供三种工作模式桥接(bridge).NAT(网络地址转换)和host-only(主机模式). NAT(网络地址转换) 在NAT模式下,虚拟系统需要借助NAT(网络地址转换)功能,通过宿主 ...

  8. PHP Socket实现websocket(四)Select函数

    int select(int maxfdp,fd_set *readfds,fd_set *writefds,fd_set *errorfds,struct timeval *timeout); /* ...

  9. Effective Java 学习笔记之创建和销毁对象

    一.考虑用静态工厂方法代替构造器 1.此处的静态工厂方法是指返回指为类的对象的静态方法,而不是设计模式中的静态工厂方法. 2.静态工厂方法的优势有: a.使用不同的方法名称可显著地表明两个静态工厂方法 ...

  10. 怎样删除一键GHOST 文件件名为~1的备份文件?

    早些时候备份过系统,但是后来觉的该备份系统不够完美,想删除.可是备份文件被保护,无法删除.(1)在网上查看了一下: start X:\~1 attrib -s -h -r X:\~1\C_PAN.GH ...