Title Link: Http://codeforces.com/problemset/problem/499/A
The title means: There are two kinds of buttons: 1, if the current viewing time is T,player can automatically process the next minute, let's understand to jump to t+1, 2, skip directly x minutes, if the player in the first T minute, you can jump to t+x. Ask for the minimum viewing time of n movies. Watch a movie to show Li, Li+1, li+2, ..., Ri-1, RI time to be covered.
It's too simple to start with, and it really takes all the time for every movie, but if you can't get to Li at that point in time, it means you're going to start overwriting at some point before Li, until RI.
My practice is to use a cur_mom to record the arrival time before the next movie. The initial time is 1 (the topic says). The question is how to determine if you can get to Li exactly, by comparing whether li-cur_mom can be divisible by x. The number of words can not arrive exactly. After finishing a movie to update cur_mom, it is equal to the end time of this movie +1.
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5 using namespacestd;6 7 intMain ()8 {9 #ifndef Online_judgeTenFreopen ("In.txt","R", stdin); One #endif //Online_judge A - intn, x; - while(SCANF ("%d%d", &n, &x)! =EOF) the { - intL, R; - intAns =0; - intCur_mom =1; + - for(inti =0; I < n; i++) + { Ascanf"%d%d", &l, &R); at if((l-cur_mom)%x) - { - intTMP = L-Cur_mom; - intnum = tmp/x; -Cur_mom + = num *x; - } in Else -Cur_mom =l; toAns + = R-cur_mom +1; +Cur_mom = r+1; - } theprintf"%d\n", ans); * } $ return 0;Panax Notoginseng}
Codeforces 499A. Inna and Pink Pony problem solving report