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);
}
}
Codeforces Round #284 (Div. 2) A的更多相关文章
- 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 ...
- Codeforces Round #284 (Div. 2)
题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...
- 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 ...
- 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 ...
- Codeforces Round #284 (Div. 2) C题(计算几何)解题报告
题目地址 简要题意: 给出两个点的坐标,以及一些一般直线方程Ax+B+C=0的A.B.C,这些直线作为街道,求从一点走到另一点需要跨越的街道数.(两点都不在街道上) 思路分析: 从一点到另一点必须要跨 ...
- Codeforces Round #284 (Div. 1)
A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. ...
- Codeforces Round #284 (Div. 1) C. Array and Operations 二分图匹配
因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦. #include<bits/stdc++.h> #define LL long long #de ...
- 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 ...
- 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 ...
随机推荐
- [Shell] echo/输出 中引用命令
# 这样是错误的,是引用变量 echo "/Users/${whoami}/Desktop" >>> /Users//Desktop # 正确的写法应该是使用`` ...
- CorelDRAWX8新功能摆脱传统工作模式
最近,有一则好消息CorelDRAW X8特惠啦!功能不少价格却不高的CDR X8很快成了设计师们的新宠,三折之后你动心了么? 点击这里了解更多.. 那么CDR X8到底有何功能和亮点呢? 完全可自定 ...
- 企业级任务调度框架Quartz(6) 任务调度器(Scheduler)
前序: 我们已经在前面的内容能里看到了,我们用 Scheduler 来管理我们的 Job:创建并关联触发器以使 Job 能被触发执行:以及如可选择 calendar 为给定的时程安排提供更多 ...
- 当li设置为line-block时,元素之间出现间隙的原因和解决方法
原因 因为浏览器默认把inline元素之间的空白符(Tab.空格.换行)渲染成一个空格.而如下述代码,两个li元素之间的换行符被渲染成一个空格,则元素之间产生了间隙. 用Chrome浏览器将场景模拟出 ...
- CF43A Football
CF43A Football 题意翻译 题目大意 两只足球队比赛,现给你进球情况,问哪支队伍赢了. 第一行一个整数nn (1\leq n\leq 1001≤n≤100 ),表示有nn 次进球,接下来n ...
- Hadoop使用Java进行文件修改删除操作
Hadoop使用Java进行文件修改删除操作 学习了:http://blog.csdn.net/menghuannvxia/article/details/44651061 学习了:http://bl ...
- EntityFramework 找不到方法:“Void System.Data.Entity.DbModelBuilder.RegisterEntityType
问题原因,EF当前版本没有该方法,将EF版本升级即可. 1.packages.config <package id="EntityFramework" version=&qu ...
- Directx Matrix.PerspectiveFovLH Matrix.PerspectiveFovRH的理解
该函数一个四个参数public static Matrix PerspectiveFovLH ( float fieldOfViewY, float aspectRatio, float znearP ...
- 【DataStructure】The difference among methods addAll(),retainAll() and removeAll()
In the Java collection framework, there are three similar methods, addAll(),retainAll() and removeAl ...
- angularjs1--动画
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...