洛谷 P5708、P5714、P5720、P5725、P5726、P5732、P5738 题解
生活随笔
收集整理的這篇文章主要介紹了
洛谷 P5708、P5714、P5720、P5725、P5726、P5732、P5738 题解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- P5708 題目要求
- P5708 AC代碼(Java語言描述)
- P5714 題目要求
- P5714 AC代碼(Java語言描述)
- P5720 題目要求
- P5720 AC代碼(Java語言描述)
- P5725 題目要求
- P5725 AC代碼(Java語言描述)
- P5726 題目要求
- P5726 AC代碼(Java語言描述)
- P5732 題目要求
- P5732 AC代碼(Java語言描述)
- P5738 題目要求
- P5738 AC代碼(Java語言描述)
P5708 題目要求
P5708題目鏈接
P5708 AC代碼(Java語言描述)
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);double a = scanner.nextDouble(), b = scanner.nextDouble(), c = scanner.nextDouble(), p = (a+b+c)/2;System.out.printf("%.1f", Math.sqrt(p*(p-a)*(p-b)*(p-c)));scanner.close();} }P5714 題目要求
P5714題目鏈接
P5714 AC代碼(Java語言描述)
import java.util.Scanner;public class Main {/*** 有效數字*/private static double roundToSignificantFigures(double num, int n) {if(num == 0) {return 0;}double d = Math.ceil(Math.log10(Math.abs(num)));int power = n - (int) d;double magnitude = Math.pow(10, power);long shifted = Math.round(num*magnitude);return shifted/magnitude;}public static void main(String[] args) {Scanner scanner = new Scanner(System.in);double result = roundToSignificantFigures(scanner.nextDouble()/Math.pow(scanner.nextDouble(), 2), 6);scanner.close();if (result < 18.5) {System.out.println("Underweight");} else if (result < 24) {System.out.println("Normal");} else {System.out.println(result + "\nOverweight");}}}P5720 題目要求
P5720題目鏈接
P5720 AC代碼(Java語言描述)
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int length = scanner.nextInt();scanner.close();int counter = 1;while (length > 1) {length/=2;counter++;}System.out.println(counter);} }P5725 題目要求
P5725題目鏈接
P5725 AC代碼(Java語言描述)
import java.util.Scanner;public class Main {public static void main(String[] args) {String var1 = "01\n\n01";String var2 = "0102\n0304\n\n 01\n0203";String var3 = "010203\n040506\n070809\n\n 01\n 0203\n040506";String var4 = "01020304\n05060708\n09101112\n13141516\n\n 01\n 0203\n 040506\n07080910";String var5 = "0102030405\n0607080910\n1112131415\n1617181920\n2122232425\n\n";String var6 = " 01\n 0203\n 040506\n 07080910\n1112131415";String var7 = "010203040506\n070809101112\n131415161718\n192021222324\n252627282930\n313233343536\n\n";String var8 = " 01\n 0203\n 040506\n 07080910\n 1112131415\n161718192021";String var9 = "01020304050607\n08091011121314\n15161718192021\n22232425262728\n29303132333435\n";String var10 = "36373839404142\n43444546474849\n\n";String var11 = " 01\n 0203\n 040506\n 07080910\n 1112131415\n";String var12 = " 161718192021\n22232425262728";String var13 = "0102030405060708\n0910111213141516\n1718192021222324\n2526272829303132\n";String var14 = "3334353637383940\n4142434445464748\n4950515253545556\n5758596061626364\n\n";String var15 = " 01\n 0203\n 040506\n 07080910\n 1112131415\n";String var16 = " 161718192021\n 22232425262728\n2930313233343536";String var17 = "010203040506070809\n101112131415161718\n192021222324252627\n282930313233343536\n";String var18 = "373839404142434445\n464748495051525354\n555657585960616263\n646566676869707172\n";String var19 = "737475767778798081\n\n";String var20 = " 01\n 0203\n 040506\n 07080910\n 1112";String var21 = "131415\n 161718192021\n 22232425262728\n 2930313233343536\n373839404142434445";Scanner scanner = new Scanner(System.in);int num = scanner.nextInt();scanner.close();switch (num) {case 1:System.out.println(var1);break;case 2:System.out.println(var2);break;case 3:System.out.println(var3);break;case 4:System.out.println(var4);break;case 5:System.out.println(var5+var6);break;case 6:System.out.println(var7+var8);break;case 7:System.out.println(var9+var10+var11+var12);break;case 8:System.out.println(var13+var14+var15+var16);break;default:System.out.println(var17+var18+var19+var20+var21);break;}} }P5726 題目要求
P5726題目鏈接
P5726 AC代碼(Java語言描述)
import java.util.Arrays; import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int num = scanner.nextInt();int[] grades = new int[num];for (int i = 0; i < num; i++) {grades[i] = scanner.nextInt();}scanner.close();Arrays.sort(grades);int sum = 0;for (int i = 1; i < num-1; i++) {sum += grades[i];}System.out.printf("%.2f", ((double)sum/(num-2)));} }P5732 題目要求
P5732題目鏈接
P5732 AC代碼(Java語言描述)
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int num = scanner.nextInt();scanner.close();int[][] array = new int[num][num];for (int i = 0; i < num; i++) {for (int j = 0; j <= i; j++) {array[i][j] = 1;}}for (int i = 1; i < num; i++) {for (int j = 0; j < i; j++) {if (j == 0) {array[i][j] = array[i-1][j];} else {array[i][j] = array[i-1][j] + array[i-1][j-1];}}}for (int i = 0; i < num; i++) {StringBuilder builder = new StringBuilder();for (int j = 0; j <= i; j++) {builder.append(array[i][j]).append(' ');}System.out.println(builder.toString().trim());}} }P5738 題目要求
P5738題目鏈接
P5738 AC代碼(Java語言描述)
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n = scanner.nextInt(), m = scanner.nextInt();double max_sum = 0.0;for (int i = 0; i < n; i++) {int sum_temp = scanner.nextInt(), max_temp = sum_temp, min_temp = sum_temp;for (int j = 1; j < m; j++) {int temp = scanner.nextInt();if (temp > max_temp) {max_temp = temp;} else if (temp < min_temp) {min_temp = temp;}sum_temp += temp;}sum_temp -= max_temp;sum_temp -= min_temp;max_sum = Math.max(max_sum, (double)sum_temp/(m-2));}scanner.close();System.out.printf("%.2f", max_sum);} }總結
以上是生活随笔為你收集整理的洛谷 P5708、P5714、P5720、P5725、P5726、P5732、P5738 题解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【UML】用例图中<<extend>>与
- 下一篇: 【MySQL】基于MySQL的SQL核心