人人笔试第三题,显示屏哪个为什么一个样例都通不过?
发布于 2017-09-13 19:54 1976 次浏览 0 赞 最后一次编辑是 2017-09-13 21:17 来自 我要提问  

如题,本地测试是可以的!!!!

更新:

求第三题显示屏的AC代码。下面是我的,通过10%。。。。

public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            // 先考虑不旋转的最大尺寸
            int i = a / x;
            int j = b / y;
            int max_a = 0, max_b = 0;
            int max_area = 0;
            if(i * y <= b) {
                max_a = i*x;
                max_b = i*y;
                max_area = max_a*max_b;
            } else {
                max_a = j*x;
                max_b = j*y;
                max_area = max_a*max_b;
            }
            i = a/y;
            j = b/x;
            if(i * x <= b) {
                if(max_area < i*y*i*x) {
                    max_a = i * x;
                    max_b = i * y;
                    max_area = max_a * max_b;
                }
            } else {
                if(max_area < j*y*j*x) {
                    max_a = j * x;
                    max_b = j * y;
                    max_area = max_a * max_b;
                }
            }
            System.out.println(max_a + " " + max_b);
        }
    }
}


2 条回复

...

2017-09-13 21:09

40%的路过

不知道为啥不Ac?

题意理解错了???

不是很懂



import java.util.Scanner;


public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while(sc.hasNextLine()) {

int a = sc.nextInt();

int b = sc.nextInt();

int x = sc.nextInt();

int y = sc.nextInt();

int[] arr = func(a,b,x,y);

System.out.println(arr[0] + " " + arr[1]);

}

}


private static int[] func(int a, int b, int x, int y) {

int[] arr = new int[2];

if(a < x || b < y) {

return arr;

}

if((a * 1.0 / x) < (b * 1.0 / y)) {

arr[0] = (a / x) * x;

arr[1] = (a / x) * y;

}else {

arr[0] = (b / y) * x;

arr[1] = (b / y) * y;

}

return arr;

}


}



2017-09-13 21:29
添加回复
回到顶部