解题思路:给出 n个电影的精彩时段(a[i],b[i]),和每次可以跳过的时间x,问要看完所有的精彩时刻,至少需要看多长时间的电影。 因为要时间最少,所有除了精彩时刻的电影则能跳过就跳过(用取余来算),不能跳过则加到耗费的总时间里面。

反思:WA两次是因为没有搞清楚物理上的时刻和时间的关系,

-------------------------------------------------- 1    2     3     4      5      6       7       8

如果我们给出一个电影精彩时段为(5,6)(表示的意思是从第5min开始到第6min结束,共持续了2min) 那么在上图的数轴中,它的长度为7-5=2 因为6这一点是第6min的开始,7这一点是第6min的结束,所以区间(6,7)代表整个第6min

A. Watching a movie

Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. Skip exactly x minutes of the movie (x is some fixed positive integer). If the player is now at the t-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (t + x). Initially the movie is turned on in the player on the first minute, and you want to watch exactly n best moments of the movie, the i-th best moment starts at the li-th minute and ends at the ri-th minute (more formally, the i-th best moment consists of minutes: li, li + 1, ..., ri).

Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?

Input The first line contains two space-separated integers n, x (1 ≤ n ≤ 50, 1 ≤ x ≤ 105) — the number of the best moments of the movie and the value of x for the second button.

The following n lines contain the descriptions of the best moments of the movie, the i-th line of the description contains two integers separated by a space li, ri (1 ≤ li ≤ ri ≤ 105).

It is guaranteed that for all integers i from 2 to n the following condition holds: ri - 1 < li.

Output Output a single number — the answer to the problem.

Sample test(s)

input

2 3

5 6

10 12

output

6

input

1 1

1 100000

output

100000

#include<stdio.h>
#include<string.h>
int a[10010],b[10010]; int main()
{
int n,x,i,t,sum;
while(scanf("%d %d",&n,&x)!=EOF)
{
sum=0;
for(i=1;i<=n;i++)
scanf("%d %d",&a[i],&b[i]);
b[0]=0;
for(i=1;i<=n;i++)
{ sum+=(a[i]-b[i-1]-1)%x+b[i]-a[i]+1;
}
printf("%d\n",sum);
}
}

  

Codeforces Round #284 (Div. 2) A的更多相关文章

  1. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #284 (Div. 2)

    题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...

  3. Codeforces Round #284 (Div. 1) A. Crazy Town 计算几何

    A. Crazy Town 题目连接: http://codeforces.com/contest/498/problem/A Description Crazy Town is a plane on ...

  4. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图最大匹配

    题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 se ...

  5. Codeforces Round #284 (Div. 2) C题(计算几何)解题报告

    题目地址 简要题意: 给出两个点的坐标,以及一些一般直线方程Ax+B+C=0的A.B.C,这些直线作为街道,求从一点走到另一点需要跨越的街道数.(两点都不在街道上) 思路分析: 从一点到另一点必须要跨 ...

  6. Codeforces Round #284 (Div. 1)

    A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. ...

  7. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图匹配

    因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦. #include<bits/stdc++.h> #define LL long long #de ...

  8. Codeforces Round #284 (Div. 2) D. Name That Tune [概率dp]

    D. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. Codeforces Round #284 (Div. 1) B. Name That Tune(概率DP)(难)

    B. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. RabbitMQ学习之基于spring-rabbitmq的消息异步发送

    spring-rabbitmq的源码到http://github.com/momania/spring-rabbitmq下载,并可以下载实例代码.由于我使用的rabbitmq版本是3.0.4,部分代码 ...

  2. python django整理(五)配置favicon.ico,解决警告Not Found: /favicon.ico(转载)

    版权声明:本文为博主原创文章,欢迎交流分享,未经博主允许不得转载. https://blog.csdn.net/HHTNAN/article/details/78549561 Django 浏览器打开 ...

  3. class一些内置方法

    一. __getattribute__ class Foo: def __init__(self,x): self.x=x def __getattr__(self, item): print('执行 ...

  4. IOS让自定义类是用下标

    在ios中,有个非常有用的特性,就是可以为自己写的类增加下标访问功能. 如果我们自己的类中有个数组items,我们想直接给类加下标的方式来访问这个数组的元素,就像访问系统的数组一样,其实只要增加一个方 ...

  5. select的option触发事件

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  6. nyoj28-大数阶乘

    大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数m(0& ...

  7. redis_1 安装和简单使用

    前言: mysql 数据库:数据以“文件形式存储在硬盘”里面.硬盘的存取速度很慢.数据库是一个系统中最占用资源的部分.当sql语句比较复杂(关联的表比较多的时候),每执行一次就会消耗大量的资源.倘若一 ...

  8. JavaScript 事件对内存和性能的影响

    程序代码: <%-- Created by IntelliJ IDEA. User: 乔克叔叔 Date: 2017/12/26 Time: 16:45 To change this templ ...

  9. js中Number()、parseInt()和parseFloat()的区别进行详细介绍

    http://www.jb51.net/article/100606.htm 区别: parseFloat,parseInt  解析的过程中如果前面有空格,结果不会有任何影响,Number解析的时候结 ...

  10. BA-冷源系统--一次流量控制方案(转载)

    空调水变一次流量控制方案 浙大网新快威科技 黄逸林 一.引言 建筑物中央空调系统的冷冻水一次泵,传统上都采用固定转速水泵.空调水的变一次流量控制系统(VPF:Variable-Primary-Flow ...