zoukankan      html  css  js  c++  java
  • Far Manager Gym

    Pavel loves Far Manager very much. By default, Far shows files in a certain number of columns each of which holds p files. Besides, there is also a «zero file» — the link to the parent directory, after which the files in the current directory are shown.

    Pavel is viewing a directory with n files numbered from 1 to n. He needs to select the file x. To do that, he has to place the cursor onto this file. He can press any of the four arrow keys: up / down arrows move the cursor by 1 file, and left / right arrows move it by p files (or place the cursor onto the «zero file» or the last file if less than p files remains in the cursor's movement direction).

    Your task is to help Pavel to determine the minimum number of key presses to select the file x. At the beginning the cursor points to the link to the parent directory.

    Input

    The only line contains 3 integers pn and x (1 ≤ p ≤ 1091 ≤ n ≤ 1091 ≤ x ≤ n) — the maximum number of files in a column, the total number of files in the directory viewed by Pavel and the file he wants to select.

    Output

    Write one integer — the minimum number of key presses Pavel needs to select the file x.

    Examples

    Input
    5 8 3
    Output
    3
    Input
    6 20 14
    Output
    4
    Input
    8 33 33
    Output
    5
    #include <stdio.h>
    #include <string.h>
    
    long long min(long long x, long long y)
    {
        if(x<y) return x;
        else return y;
    }
    
    int main()
    {
        long long p, n, x, ree, shang, yu, re;
        scanf("%lld %lld %lld", &p, &n, &x);
    
        shang = x / p;
        yu = x % p;
        re = shang + yu;
    
        shang++;
        yu = min(n-x, shang*p-x);
        ree = shang + yu;
        if(ree<re) re = ree;
    
    
    
        x = n - x;
    
        shang = x / p;
        yu = x % p;
        ree = yu + shang + n/p;
        if(n%p>0) ree++;
        if(ree < re) re = ree;
    
        shang++;
        yu = min(n-x, shang*p-x);
        ree = yu + shang + n/p;
        if(n%p>0) ree++;
        if(ree < re) re = ree;
    
    
        printf("%lld
    ", re);
        return 0;
    }
     
     
     
     
  • 相关阅读:
    【SQL跟踪工具】SQL Profiler 跟踪器
    使用Fiddler调试手机端页面请求/抓包
    SQL 常用判断语句
    VS中常用快捷键
    博客园博客自动生成目录/目录索引
    BZOJ 1135 P3488 LYZ-Ice Skates 线段树+Hall
    BZOJ 4823 老C的方块
    POJ
    BZOJ 1299 [LLH邀请赛]巧克力棒
    BZOJ 2437 [Noi2011]兔兔与蛋蛋
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11671246.html
Copyright © 2011-2022 走看看