2011年2月22日火曜日

Aizu Online Judge 0166 Area of Polygon

■0166 Area of Polygon

中心角θの三角形の面積は,2sin(θ/2)

  1. import java.util.*;  
  2. import java.lang.*;  
  3. import java.math.*;  
  4. import java.io.*;  
  5.   
  6. import static java.lang.Math.*;  
  7. import static java.util.Arrays.*;  
  8.   
  9. public class Main{  
  10.   
  11.  Scanner sc=new Scanner(System.in);  
  12.   
  13.  int INF=1<<28;  
  14.  double EPS=1e-9;  
  15.   
  16.  void run(){  
  17.   for(;;){  
  18.    double[] area=new double[2];  
  19.    for(int j=0; j<2; j++){  
  20.     int m=sc.nextInt();  
  21.     if(m==0){  
  22.      return;  
  23.     }  
  24.     int sum=0;  
  25.     for(int i=0; i<m-1; i++){  
  26.      int deg=sc.nextInt();  
  27.      area[j]+=Math.sin(Math.toRadians(deg/2))*2;  
  28.      sum+=deg;  
  29.     }  
  30.     area[j]+=Math.sin(Math.toRadians(360-sum))/2;  
  31.    }  
  32.    if(area[0]>area[1]+EPS){  
  33.     println("1");  
  34.    }else if(area[0]+EPS<area[1]){  
  35.     println("2");  
  36.    }else{  
  37.     println("0");  
  38.    }  
  39.   }  
  40.  }  
  41.   
  42.  void debug(Object... os){  
  43.   System.err.println(Arrays.deepToString(os));  
  44.  }  
  45.   
  46.  void print(String s){  
  47.   System.out.print(s);  
  48.  }  
  49.   
  50.  void println(String s){  
  51.   System.out.println(s);  
  52.  }  
  53.   
  54.  public static void main(String[] args){  
  55.   // System.setOut(new PrintStream(new BufferedOutputStream(System.out)));  
  56.   new Main().run();  
  57.  }  
  58. }  

0 件のコメント: