結果
問題 | No.764 浮動点 |
ユーザー |
|
提出日時 | 2018-12-01 19:47:38 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 280 ms / 1,500 ms |
コード長 | 3,531 bytes |
コンパイル時間 | 2,368 ms |
コンパイル使用メモリ | 78,872 KB |
実行使用メモリ | 45,780 KB |
最終ジャッジ日時 | 2024-06-27 00:02:23 |
合計ジャッジ時間 | 9,748 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
import java.util.*;import java.io.*;import java.math.*;class Main{public static void main(String[] args){new Main().run();}void run(){Scanner sc=new Scanner();int N=sc.nextInt();double[] L=new double[N+2];for(int i=0;i<=N+1;++i){L[i]=sc.nextInt();}double[] Ri1=new double[N+2];double[] Ro1=new double[N+2];double[] Ri2=new double[N+2];double[] Ro2=new double[N+2];for(int i=1;i<=N;++i){Ro1[i]=Ro1[i-1]+L[i];}Ri1[1]=Ro1[1];for(int i=2;i<=N;++i){Ri1[i]=abs(Ri1[i-1],Ro1[i-1],L[i]);}for(int i=N;i>=1;--i){Ro2[i]=Ro2[i+1]+L[i+1];}Ri2[N]=Ro2[N];for(int i=N-1;i>=1;--i){Ri2[i]=abs(Ri2[i+1],Ro2[i+1],L[i+1]);}for(int i=1;i<=N;++i){System.out.println(String.format("%.20f",solve(Ro1[i],Ri1[i],Ro2[i],Ri2[i],L[0])));}}double solve(double Ro1,double Ri1,double Ro2,double Ri2,double L){return f(Ro1,Ro2,L)-f(Ro1,Ri2,L)-f(Ri1,Ro2,L)+f(Ri1,Ri2,L);}double abs(double a,double b,double d){if(a<=d&&d<=b)return 0;return Math.min(Math.abs(d-a),Math.abs(d-b));}double f(double a,double b,double L){if(L>=a+b)return 0;if(b>=a+L)return a*a*Math.PI;if(a>=b+L)return b*b*Math.PI;double x=0.5*L+(a*a-b*b)/(2*L);double y=Math.sqrt(a*a-x*x);double ang1=Math.atan2(y,x);double ang2=Math.atan2(y,L-x);if(ang1<0)ang1+=Math.PI;if(ang2<0)ang2+=Math.PI;return g(2*ang1,a)+g(2*ang2,b);}double g(double ang,double r){return 0.5*r*r*(ang - Math.sin(ang));}void tr(Object...o){System.out.println(Arrays.deepToString(o));}}class Scanner {private final InputStream in = System.in;private final byte[] buffer = new byte[1024];private int ptr = 0;private int buflen = 0;private boolean hasNextByte() {if (ptr < buflen) {return true;}else{ptr = 0;try {buflen = in.read(buffer);} catch (IOException e) {e.printStackTrace();}if (buflen <= 0) {return false;}}return true;}private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}public boolean hasNext() { skipUnprintable(); return hasNextByte();}public String next() {if (!hasNext()) throw new NoSuchElementException();StringBuilder sb = new StringBuilder();int b = readByte();while(isPrintableChar(b)) {sb.appendCodePoint(b);b = readByte();}return sb.toString();}public long nextLong() {if (!hasNext()) throw new NoSuchElementException();long n = 0;boolean minus = false;int b = readByte();if (b == '-') {minus = true;b = readByte();}if (b < '0' || '9' < b) {throw new NumberFormatException();}while(true){if ('0' <= b && b <= '9') {n *= 10;n += b - '0';}else if(b == -1 || !isPrintableChar(b)){return minus ? -n : n;}else{throw new NumberFormatException();}b = readByte();}}public int nextInt(){return (int)nextLong();}}