2012/03/05

[zerojudge] d485 我愛偶數

題目:https://zerojudge.tw/ShowProblem?problemid=d485
說明:偏向分析及數學相關問題。

Java 版
import java.util.Scanner;
import java.lang.Math;

public class D485 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String[] str = in.nextLine().split(" ");
            double a = Double.parseDouble(str[0]);
            double b = Double.parseDouble(str[1]);
            int r = (int) Math.ceil((b-a+1 - (b % 2)) / 2);
            System.out.println(r);
        }
    }
}
Python 版 (2022.07)
import math

while True:
    try:
        a, b = map(int, input().split(' '))
        r = math.ceil((b-a+1 - (b % 2)) / 2);
        print(r)
    except:
        break

沒有留言:

張貼留言