洛谷入门题P1008、P1035、P1423、P1424、P1980题解(Java语言描述)
生活随笔
收集整理的這篇文章主要介紹了
洛谷入门题P1008、P1035、P1423、P1424、P1980题解(Java语言描述)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
P1008題目描述
P1008題目鏈接
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 981P1035題目描述
P1035題目鏈接
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題目鏈接
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題目鏈接
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題目鏈接
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();} }沒啥可講解的,很容易就完事
總結
以上是生活随笔為你收集整理的洛谷入门题P1008、P1035、P1423、P1424、P1980题解(Java语言描述)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Java】OpenJDK 64-Bit
- 下一篇: 【Python】Matplotlib绘制