Submission #3773077
Source Code Expand
import java.util.Arrays; import java.util.InputMismatchException; import java.util.Scanner; public class Main{ /** * 全体処理 * @param args */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub int n = 0; n = input(); calc(n); } /** * 計算 * @param n * @throws Exception */ private static void calc(int n) throws Exception { // TODO Auto-generated method stub boolean flag = true; double pi = Math.PI; //System.out.println(flag); Scanner sc = null; int[] c = new int[n]; try { sc = new Scanner(System.in); int i = 0; while (i < n) { // System.out.println("第"+(i+1)+"番の円を入力してください: "); c[i] = sc.nextInt(); i++; } } catch (InputMismatchException e) { System.out.println("error"); } finally { sc.close(); } Arrays.sort(c); // nは奇数、偶数を判断する if (n % 2 == 0) { flag = false; } double sum_r =0,sum_w=0; double menseki_r=0,menseki_w=0; if (flag = true)// 奇数の場合 { // System.out.println("円の数が奇数"); for(int i=0;i<n;i++) { if(i%2==0) { // System.out.println(i+"番偶数"); menseki_r = Math.pow(c[i], 2)*pi; //System.out.println("面積赤"+menseki_r); sum_r = sum_r + menseki_r; } else { //System.out.println(i+"番奇数"); menseki_w = Math.pow(c[i], 2)*pi; //System.out.println("面積白"+menseki_w); sum_w = sum_w + menseki_w; } } //System.out.println("赤い部分面積:"+Math.abs(sum_r - sum_w)); System.out.println(Math.abs(sum_r - sum_w)); } else if (flag = false)// 偶数の場合 { //System.out.println("円の数が偶数"); for(int i=0;i<n;i++) { if(i%2!=0) { menseki_r = Math.pow(c[i], 2)*pi; sum_r = sum_r + menseki_r; } else { menseki_r = Math.pow(c[i], 2)*pi; sum_w = sum_w + menseki_w; } } //System.out.println("赤い部分面積:"+Math.abs(sum_r - sum_w)); System.out.println(Math.abs(sum_r - sum_w)); } else { throw new Exception("input error calc"); } } /** * 入力処理 * @return */ private static int input() { // TODO Auto-generated method stub Scanner sc = null; try { sc = new Scanner(System.in); //System.out.println("円の数を入力してください:"); int n; n = sc.nextInt(); return n; } catch (InputMismatchException e) { System.out.println("input error input"); } finally { //sc.close(); } return 0; } }
Submission Info
Submission Time | |
---|---|
Task | B - N重丸 |
User | James |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 3705 Byte |
Status | RE |
Exec Time | 105 ms |
Memory | 24916 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_0.txt, example_1.txt |
All | example_0.txt, example_1.txt, maxrand_0.txt, maxrand_1.txt, maxrand_2.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, special_0.txt, special_1.txt, special_2.txt, special_3.txt, example_0.txt, example_1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_0.txt | RE | 105 ms | 24916 KB |
example_1.txt | RE | 99 ms | 18644 KB |
maxrand_0.txt | RE | 99 ms | 22100 KB |
maxrand_1.txt | RE | 99 ms | 19156 KB |
maxrand_2.txt | RE | 100 ms | 20552 KB |
random_0.txt | RE | 99 ms | 21204 KB |
random_1.txt | RE | 100 ms | 19796 KB |
random_2.txt | RE | 98 ms | 20688 KB |
random_3.txt | RE | 102 ms | 19412 KB |
random_4.txt | RE | 100 ms | 21588 KB |
random_5.txt | RE | 99 ms | 19796 KB |
random_6.txt | RE | 101 ms | 18644 KB |
random_7.txt | RE | 101 ms | 22740 KB |
random_8.txt | RE | 100 ms | 18644 KB |
random_9.txt | RE | 100 ms | 21460 KB |
special_0.txt | RE | 102 ms | 18900 KB |
special_1.txt | RE | 100 ms | 21716 KB |
special_2.txt | RE | 102 ms | 20692 KB |
special_3.txt | RE | 102 ms | 19412 KB |