1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import java.util.Scanner; /** * UVA10783 */ public class UVA10783 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int time = sc.nextInt(); for (int i = 0; i < time; i++) { int n1 = sc.nextInt(), n2 = sc.nextInt(), sum = 0; for (int j = n1; j <= n2; j++) if ((j & 0x00000001) == 1) sum += j; System.out.printf("Case %d: %d\r\n", i + 1, sum); } sc.close(); } } |
日期: 2018 年 5 月 23 日
Java – UVA10812
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(); } } |
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(); } } |