Codeforces 499A. Inna and Pink Pony problem solving report

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.