Codeforces Round #284 (Div. 2) A

解题思路:给出 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);
	}
}

  

时间: 2024-10-26 21:45:09

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

Codeforces Round #284 (Div. 2) b

/**  * @brief Codeforces Round #284 (Div. 2) b  * @file b.cpp  * @author mianma  * @created 2014/12/26 11:51  * @edited  2014/12/18 11:51  * @type brute  * @note  */ #include <fstream> #include <iostream> #include <string> #include <c

[Codeforces Round #284 (Div. 1) B]Name That Tune(概率Dp)

Description It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the name of the song. After you tell the so

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

题目地址 简要题意: 给出两个点的坐标,以及一些一般直线方程Ax+B+C=0的A.B.C,这些直线作为街道,求从一点走到另一点需要跨越的街道数.(两点都不在街道上) 思路分析: 从一点到另一点必须要跨的街道等价于两点一点在这条直线一侧,另一条在另一侧.只需要将两点坐标带进去,一正一负即可.将这些直线依次检验,统计总和. 1 #include<stdio.h> 2 #include<bits/stdc++.h> 3 #include <iostream> 4 using

Codeforces Round #284 (Div. 1)

A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. 代码: 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<string> 5 #include<map> 6 #define N 100010 7 #def

Codeforces Round #284 (Div. 2)

Problem C 题目大意:一个平面内有一些无限长的直线,把平面分成了若干块,从一块走一步可以走到与它有公共边的另一块,但是只有公共点不能一步走过去.给定两个在块内部的点,问从S点到T点最少走几步. 题目分析:由于每步只能跨越公共边,不能从两直线交点处跨越,所以一步只能越过 S 与 T 之间的一条直线,那么答案就是 S 与 T 之间有多少条直线(即 S 与 T 在这些直线的两侧).判断 S 与 T 在直线 l 两侧 :  l : ax + by + c = 0        (a*Sx + b

Codeforces Round #284 (Div.1) Solution

A 有意思,初看觉得怎么A还要求线交还这么麻烦.仔细一想.每次只能过一条线.如果有一条线在两点间,则必须过它们.在同侧的线不需要过.于是就简单了. B 时限好紧,我用了一个诡异的方法的时间复杂也是O(nT)却超了. C 奇数和偶数显然形成了二分图.对每一个素因子来一次最大流. D 首先注意到模LCM的60,噢.由于之前那个题,一下就想到分块大法好.什么嘛,明明就可以线段树呀.

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

题面 题意:给你2个点A和B,和n条直线(ax+by+c=0),给n个a,b,c,求A到B至少跨过多少条直线 题解:对于每条直线,看2个点是否在他同侧,异侧答案就+1 1 #include<bits/stdc++.h> 2 using namespace std; 3 double x1,x2,y11,y2,a,b,c,t1,t2; 4 int n,ans; 5 int main() 6 { 7 cin>>x1>>y11; 8 cin>>x2>>

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

因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #defin

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/