题解 | #猜数#

猜数

https://www.nowcoder.com/practice/3eb9a66c7fa24b90845271f6b80b7092

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        while(in.hasNext()){
            solution(in);
        }
    }

    /**
     * 数学法
     * 举例子找规律
     * @param in
     */
    private static void solution(Scanner in){
        long x = in.nextLong();
        long y = in.nextLong();

        long half = y/2;
        long result = 0;
        if(x > half){
            if(x < y){
                result = x-half;
            }else{
                // 再减1 多了0+y这个组合
                result = y-half-1;
            }
        }

        System.out.println(result);
    }
}

全部评论

相关推荐

牛至超人:我将凌晨两点给你打电话
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务