Submission #3773115


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;
        
            sc = new Scanner(System.in);
            //System.out.println("円の数を入力してください:");
            int n;
            n = sc.nextInt();
            return n;
      

    }

}

Submission Info

Submission Time
Task B - N重丸
User James
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 3528 Byte
Status RE
Exec Time 96 ms
Memory 23252 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
RE × 2
RE × 21
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 94 ms 19924 KB
example_1.txt RE 95 ms 20560 KB
maxrand_0.txt RE 95 ms 20564 KB
maxrand_1.txt RE 95 ms 19540 KB
maxrand_2.txt RE 94 ms 19924 KB
random_0.txt RE 94 ms 21844 KB
random_1.txt RE 94 ms 21204 KB
random_2.txt RE 94 ms 20820 KB
random_3.txt RE 94 ms 21972 KB
random_4.txt RE 95 ms 18772 KB
random_5.txt RE 94 ms 19284 KB
random_6.txt RE 95 ms 20692 KB
random_7.txt RE 95 ms 21716 KB
random_8.txt RE 96 ms 21460 KB
random_9.txt RE 94 ms 19796 KB
special_0.txt RE 94 ms 19156 KB
special_1.txt RE 95 ms 18644 KB
special_2.txt RE 95 ms 21716 KB
special_3.txt RE 96 ms 23252 KB