1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import java.util.Scanner; /** * UVA10812 */ public class UVA10812 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int time = sc.nextInt(); for (int i = 0; i < time; i++) { int S = sc.nextInt(), D = sc.nextInt(); int n1 = 0, n2 = 0; n1 = S + D; if (n1 % 2 != 0) System.out.println("impossible"); else { n1 /= 2; n2 = S - n1; if (n1 < 0 || n2 < 0) System.out.println("impossible"); else System.out.printf("%d %d\r\n", n1, n2); } } sc.close(); } } |
月份: 2018 年 5 月
Java – UVA11349
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import java.util.Scanner; /** * UVA11349 */ public class UVA11349 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int time = sc.nextInt(); for (int i = 0; i < time; i++) { sc.next(); sc.next(); int size = sc.nextInt(); int[] matrix = new int[size * size]; int index = 0; for (int j = 0; j < size; j++) { for (int k = 0; k < size; k++) { matrix[index] = sc.nextInt(); index++; } } boolean flag = true; for (int j = 0; j <= matrix.length / 2; j++) if (matrix[j] != matrix[matrix.length - 1 - j] || matrix[j] < 0 || matrix[matrix.length - 1 - j] < 0) { flag = false; break; } System.out.printf("Test #%d: %s.\r\n", i + 1, flag ? "Symmetric" : "Non-symmetric"); } sc.close(); } } |
Java – UVA10268
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import java.util.Scanner; /** * UVA10268 */ public class UVA10268 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextLine()) { int x = Integer.parseInt(sc.nextLine()); String[] str = sc.nextLine().split(" "); int[] intArray = new int[str.length]; int sum = 0; for (int i = 0; i < intArray.length; i++) intArray[i] = Integer.parseInt(str[i]); for (int i = 0; i < intArray.length - 1; i++) sum += intArray[i] * (intArray.length - 1 - i) * Math.pow(x, intArray.length - 2 - i); System.out.println(sum); } sc.close(); } } |
Java – UVA10170
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import java.util.Scanner; /** * UVA10170 */ public class UVA10170 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { long S = sc.nextLong(), D = sc.nextLong(); for (long i = S; i < D; i += S) S++; System.out.println(S); } sc.close(); } } |
Java – UVA10056
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import java.util.Scanner; /** * UVA10056 */ public class UVA10056 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int time = sc.nextInt(); for (int i = 0; i < time; i++) { double n1 = sc.nextDouble(); double p = sc.nextDouble(); double n2 = sc.nextDouble(); System.out.printf("%.4f\r\n", p == 0 ? p : p * Math.pow(1 - p, n2 - 1) / (1 - Math.pow(1 - p, n1))); } sc.close(); } } |
Java – UVA10038
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import java.util.Arrays; import java.util.Scanner; /** * UVA10038 */ public class UVA10038 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextLine()) { int time = sc.nextInt(); int[] intArray = new int[time]; for (int i = 0; i < intArray.length; i++) intArray[i] = sc.nextInt(); int[] d = new int[intArray.length - 1]; for (int i = 0; i < d.length; i++) d[i] = Math.abs(intArray[i] - intArray[i + 1]); Arrays.sort(d); boolean flag = true; for (int i = 0; i < time - 1; i++) if (d[i] != i + 1) flag = false; System.out.printf("%s\r\n", flag ? "Jolly" : "Not jolly"); } sc.close(); } } |
Java – UVA12019
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.util.Scanner; /** * UVA12019 */ public class UVA12019 { public static void main(String[] args) { String days[] = new String[] { "", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", }; Scanner sc = new Scanner(System.in); int n [] = new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31}; int num = sc.nextInt(); for (int i = 0; i < num; i++) { int day = 0; int m = sc.nextInt() , d = sc.nextInt(); for(int j = m - 1 ; j >= 1 ; j--) day += n[j]; day += d; int thisday = day % 7; System.out.println(days[thisday]); } sc.close(); } } |
Java – UAV11332
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import java.util.Scanner; /** * UVA11332 */ public class UVA11332 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String temp = ""; while (sc.hasNext()) { temp = sc.nextLine(); if (temp.equals("0")) break; String s = g(temp); System.out.println(s); } } public static String g(String str) { if (str.length() <= 1) return str; else { int sum = 0; for (int i = 0; i < str.length(); i++) sum += Integer.parseInt(str.substring(i, i + 1)); return g(Integer.toString(sum)); } } } |