解题思路:给出 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. 基于Nginx服务的用户认证

    通过Nginx实现web页面的用户认证,用户名为:admin,密码为:654321 1.修改Nginx配置文件 # vim /usr/local/nginx/conf/nginx.conf ..... ...

  2. 【转载】springboot注解

    https://blog.csdn.net/yitian_66/article/details/80866571 springboot注解:@Service: 注解在类上,表示这是一个业务层bean@ ...

  3. 简单JavaScript小程序

    <!DOCTYPE html><html>    <head>        <meta charset="UTF-8">      ...

  4. Project Euler 47 Distinct primes factors( 筛法记录不同素因子个数 )

    题意: 首次出现连续两个数均有两个不同的质因数是在: 14 = 2 × 715 = 3 × 5 首次出现连续三个数均有三个不同的质因数是在: 644 = 22 × 7 × 23645 = 3 × 5 ...

  5. [luogu 1270] “访问”美术馆 (树形dp)

    传送门 Description 经过数月的精心准备,Peer Brelstet,一个出了名的盗画者,准备开始他的下一个行动.艺术馆的结构,每条走廊要么分叉为两条走廊,要么通向一个展览室.Peer知道每 ...

  6. Django入门--url路由基本配置

    URL(Uniform Resoure Locater)统一资源定位符,是对可以从互联网上得到资源位置和访问方法的一种简洁形式,是互联网上标准资源的地址.互联网上的每个文件都有一个唯一的URL,它包含 ...

  7. HDU 3567 Eight II

    Eight II Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 3 ...

  8. Shiro身份认证授权原理

    shiro在应用程序中的使用是用Subject为入口的, 最终subject委托给真正的管理者ShiroSecurityMannager Realm是Shiro获得身份认证信息和来源信息的地方(所以这 ...

  9. [asp.net]ashx中session存入,aspx为null的原因(使用flash uploader)

    I am using uploadify to upload files, they automatically post to the handler. I then modify the sess ...

  10. ZOJ 3203

    很简单的一题,注意墙上的影子是放大就行.用三分. #include <iostream> #include <cstdio> #include <cstring> ...