题解 CF499A 【Watching a movie】

The meaning of problems

Watch a movie, began to read from the first minute, every time you can press the fast-forward button, fast forward x minutes, the film has n highlights, ask to see all the highlights of at least need to see how many minutes movie. (Data guaranteed to see all the highlights)

In fact, we can find the answer

Is the interval time highlight% x +

Take the first sample

1 2 3 4 5 6 7 8 9 10 11 12

56101112 three minutes must choose, we can skip the first minute to reach the first 4 minutes (1,2,3 skipped), jump at the end of the first 6 minutes of the 10 minutes the answer is six minutes .

You can write the formula

years + = (l [i] r [i-1] -1) x%;

years + = r [i] -l [i] +1;

Since beginning to see the need for special sentence from the first minute, we can r [0] = 0 can be (as to why a 0 instead of 1, you can draw your own look, not proof), due to the global variable itself is 0, It does not require the assignment

Code

#include<bits/stdc++.h>
using namespace std;
int n,x,l[60],r[60],ans;
int main(){
    scanf("%d %d",&n,&x);
    for(int i=1;i<=n;++i){
        scanf("%d %d",&l[i],&r[i]);
    }
    for(int i=1;i<=n;++i){
        ans+=(l[i]-r[i-1]-1)%x;
        ans+=r[i]-l[i]+1;
    }
    printf("%d",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/donkey2603089141/p/11415013.html