关于第五个点

P1618 三连击(升级版)

lnnau @ 2022-10-04 10:21:20

题目没有说A:B:C的比值必须是整数,所以可以出现比值为小数的情况,这样123:456:789的比值就是1:3.xx:6.xx ,满足条件的也就为123 456 789了。加上求比值的操作和注意类型应该就过了。


by lnnau @ 2022-10-04 10:22:40

package LOQ.暴力枚举;

import java.util.Scanner;

/**
 * @[Author](/user/583141) Lunau
 * @[Create](/user/185009) 2022-10-03 17:16
 * @Description
 * @[Result](/user/311479)
 */
public class P1618三连击升级版_2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //A:B:C
        double t1 = sc.nextInt();
        double t2 = sc.nextInt();
        double t3 = sc.nextInt();
        double b,c;
        //计数器
        int count = 0;
        for(double a = 123;a<=329;a++) {
            b = a * (t2/t1);
            c = a * (t3/t1);
            if (judge(a,b,c)) {
                System.out.println((int)a+" "+(int)b+" "+(int)c);
                count++;
            }
        }
        if (count==0) {
            System.out.println("No!!!");
        }
    }
    public static Boolean judge(double a,double b,double c) {
        String str = ""+(int)a+(int)b+(int)c;
        if (str.contains("1")&&str.contains("2")&&str.contains("3")&&str.contains("4")
                &&str.contains("5")&&str.contains("6")&&str.contains("7")&&str.contains("8")&&str.contains("9")
        &&!str.contains("0")&&str.length()==9) {
            return true;
        }
        return false;
    }
}

by bowenzuo @ 2022-11-28 11:21:26

@lnnau 为什么A,B,C可以是小数?我不明白qwq


by bowenzuo @ 2022-11-28 11:22:09

@lnnau 三个数的比可以是小数么?


by lnnau @ 2023-03-18 15:36:43

@bowenzuo 是比值是小数,不是说ABC是小数


by lnnau @ 2023-03-18 15:37:00

@bowenzuo 对


by bowenzuo @ 2023-03-18 15:40:51

@lnnau 哦


|