This is an YY Problem(oj水题+从左下角到右上角(把图像向左旋转90度)进行暴力查找+画画图就出结果)

代码:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        int T = reader.nextInt();
        while (T-- > 0) {
            int n = reader.nextInt();
            int m = reader.nextInt();
            double r = 0.0;
            if (m > n) {
                int t = m;
                m = n;
                n = t;
            }
            r = n * 1.0 / m;/// 大于等于1
            int i = 1;
            int j = 1;
            double s = 0.0;
            int c = 0;
            while (i <= n && j <= m) {
                s = i * 1.0 / j;
                if (s > r) {
                    j++;
                    c++;
                } else if (s == r) {
                    i++;
                    j++;
                    c++;
                } else if (s < r) {
                    i++;
                    c++;
                }
            }
            System.out.println(c);
        }
        reader.close();
    }
}

猜你喜欢

转载自blog.csdn.net/ACMerdsb/article/details/82811065