码迷,mamicode.com
首页 > 其他好文 > 详细

问题 A: Fast Forwarding

时间:2020-09-17 23:48:52      阅读:48      评论:0      收藏:0      [点我收藏+]

标签:des   states   stream   start   cin   course   ref   second   form   

问题 A: Fast Forwarding

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

Mr. Anderson frequently rents video tapes of his favorite classic films. Watching the films so many times, he has learned the precise start times of his favorite scenes in all such films. He now wants to find how to wind the tape to watch his favorite scene as quickly as possible on his video player.

When the [play] button is pressed, the film starts at the normal playback speed. The video player has two buttons to control the playback speed: The [3x] button triples the speed, while the [1/3x] button reduces the speed to one third. These speed control buttons, however, do not take effect on the instance they are pressed. Exactly one second after playback starts and every second thereafter, the states of these speed control buttons are checked. If the [3x] button is pressed on the timing of the check, the playback speed becomes three times the current speed. If the [1/3x] button is pressed, the playback speed becomes one third of the current speed, unless it is already the normal speed.

For instance, assume that his favorite scene starts at 19 seconds from the start of the film. When the [3x] button is on at one second and at two seconds after the playback starts, and the [1/3x] button is on at three seconds and at five seconds after the start, the desired scene can be watched in the normal speed five seconds after starting the playback, as depicted in the following chart.

技术图片
Your task is to compute the shortest possible time period after the playback starts until the desired scene starts. The playback of the scene, of course, should be in the normal speed.

输入

The input consists of a single test case of the following format.
t
The given single integer t (0≤t<250) is the start time of the target scene.

输出

Print an integer that is the minimum possible time in seconds before he can start watching the target scene in the normal speed.

样例输入 Copy

【样例1】
19
【样例2】
13
【样例3】
123456789098765
【样例4】
51
【样例5】
0
【样例6】
3
【样例7】
4

样例输出 Copy

【样例1】
5
【样例2】
5
【样例3】
85
【样例4】
11
【样例5】
0
【样例6】
3
【样例7】
2

 

 

#include <iostream>

using namespace std;

typedef long long ll;

ll n;
ll cnt = 2;

int main(){
    cin >> n;
    if (n <= 3) {cout << n; return 0;}
    
    n -= 1;
    
    ll pre = 3, sum = 0, space = 3;
    while (1){
        sum = pre + space * 3 + space;
        if (sum <= n){
            pre = sum;
            space *= 3;
            cnt += 2;
        }
        else break;
    }
    
    ll end = n - pre;
    while (space > 0 && end > 0){
        cnt += (end / space);
        end %= space;
        space /= 3;
    }
    
    cout << cnt << endl;
    
    return 0;
}

  

问题 A: Fast Forwarding

标签:des   states   stream   start   cin   course   ref   second   form   

原文地址:https://www.cnblogs.com/Iamcookieandyou/p/13660516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!