欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

洛谷入门题P1008、P1035、P1423、P1424、P1980题解(Java语言描述)

程序员文章站 2024-03-17 20:59:58
...

P1008题目描述

P1008题目链接

洛谷入门题P1008、P1035、P1423、P1424、P1980题解(Java语言描述)

P1008题解

public class Main {
    private static byte[] arr = new byte[9];

    public static void main(String[] args) {
        for (int i = 123; i < 333; i++) {
            arr = new byte[9];
            int two = 2*i, three = 3*i;
            if (judge(i) && judge(two) && judge(three)) {
                System.out.println(i + " " + two + " " + three);
            }
        }
    }

    private static boolean judge(int i) {
        int a = i / 100;
        int b = (i % 100) / 10;
        int c = i - a*100 - b*10;
        if (b == 0 || c == 0 || a == b || a == c || b == c || arr[a-1] == 1 || arr[b-1] == 1 || arr[c-1] == 1) {
            return false;
        }
        arr[a-1] = arr[b-1] = arr[c-1] = 1;
        return true;
    }
}

本题答案:

192 384 576
219 438 657
273 546 819
327 654 981

P1035题目描述

P1035题目链接

洛谷入门题P1008、P1035、P1423、P1424、P1980题解(Java语言描述)

P1035题解

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        int n = 1;
        double sum = 0.0;
        while (sum <= k) {
            sum += (double)1/n;
            if (sum <= k) {
                n++;
            }
        }
        System.out.println(n);
        scanner.close();
    }
}

P1423题目描述

P1423题目链接

洛谷入门题P1008、P1035、P1423、P1424、P1980题解(Java语言描述)

P1423题解

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double range = scanner.nextDouble();
        double sum = 0.0;
        int step = 0;
        double nextStep = 2.0;
        while (sum < range) {
            sum += nextStep;
            nextStep *= 0.98;
            step++;
        }
        System.out.println(step);
        scanner.close();
    }
}

P1424题目描述

P1424题目链接

洛谷入门题P1008、P1035、P1423、P1424、P1980题解(Java语言描述)

P1424题解

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int fromDay = scanner.nextInt(), dayNum = scanner.nextInt();
        int weekdayNum = dayNum / 7 * 5;
        int leftNum = dayNum % 7;
        if (leftNum > 0) {
            if (leftNum + fromDay == 7 || fromDay == 7) {
                leftNum -= 1;
            } else if (leftNum + fromDay >= 8) {
                leftNum -= 2;
            }
        }
        System.out.println((weekdayNum + leftNum) * 250);
        scanner.close();
    }
}

P1980题目描述

P1980题目链接

洛谷入门题P1008、P1035、P1423、P1424、P1980题解(Java语言描述)

P1980题解

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int toNum = scanner.nextInt(), searchNum = scanner.nextInt();
        int[] array = new int[10];
        for (Integer i = 1; i <= toNum; i++) {
            for (char c : i.toString().toCharArray()) {
                array[c-48]++;
            }
        }
        System.out.println(array[searchNum]);
        scanner.close();
    }
}

没啥可讲解的,很容易就完事

相关标签: # 菜鸡逛洛谷