結果

問題 No.724 円と円の間の円
ユーザー te-shte-sh
提出日時 2018-08-24 17:03:15
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,211 bytes
コンパイル時間 2,468 ms
コンパイル使用メモリ 163,396 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 20:53:23
合計ジャッジ時間 3,816 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; real a, b; readV(n, a, b);

  auto c = (a+b)/2, d = (a*b).sqrt, eps = 1.0e-7L;

  struct Cir
  {
    real x, y, r;
    this(real x)
    {
      this.x = x;
      y = (d^^2 * (1 - (x-c)^^2/c^^2)).sqrt;
      r = ((x-a)^^2 + y^^2).sqrt - a;
    }
  }

  Cir e;
  if (n%2 == 1) {
    e = Cir(a+b);
    n = (n-1)/2;
  } else {
    auto calc1(real x)
    {
      auto e = Cir(x);
      return e.r - e.y;
    }
    auto bs = iota(0.0L, a+b, eps).map!(x => tuple(x, calc1(x))).assumeSorted!"a[1]<b[1]";
    auto x = bs.lowerBound(tuple(0, 0)).back[0];
    e = Cir(x);
    n = n/2-1;
  }

  auto calc(Cir e, real x2)
  {
    auto e2 = Cir(x2);
    return (e2.r+e.r) - ((e2.x-e.x)^^2+(e2.y-e.y)^^2).sqrt;
  }

  foreach (_; 0..n) {
    auto bs = iota(0.0L, e.x, eps).map!(x2 => tuple(x2, calc(e, x2))).assumeSorted!"a[1]<b[1]";
    auto x2 = bs.lowerBound(tuple(0, 0)).back[0];
    e = Cir(x2);
  }

  writefln("%.6f", e.r);
}
0