結果

問題 No.764 浮動点
ユーザー rickythetarickytheta
提出日時 2018-12-12 00:51:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 1,500 ms
コード長 1,350 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 160,080 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 22:30:02
合計ジャッジ時間 2,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 4 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 6 ms
4,348 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 5 ms
4,348 KB
testcase_21 AC 6 ms
4,348 KB
testcase_22 AC 6 ms
4,348 KB
testcase_23 AC 5 ms
4,348 KB
testcase_24 AC 6 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
main.cpp:26:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |   REP(i,n+2)scanf("%lf",l+i);
      |             ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

int n;
double l[1252];

const double PI = 4.0*atan(1.0);

double calc(double r1, double r2, double d){
  if(r1+r2<d)return 0.0;
  if(d+r1<=r2)return r1*r1*PI;
  if(d+r2<=r1)return r2*r2*PI;
  double cos1 = (d*d + r1*r1 - r2*r2) / (2*d*r1);
  double cos2 = (d*d + r2*r2 - r1*r1) / (2*d*r2);
  double theta1 = acos(cos1);
  double theta2 = acos(cos2);
  return r1*r1*theta1 + r2*r2*theta2 - d*r1*sin(theta1);
}

int main(){
  scanf("%d",&n);
  REP(i,n+2)scanf("%lf",l+i);
  FOR(i,1,n+1){
    double maxlen1 = 0.0, minlen1 = 0.0;
    {
      double sm = 0.0, mx = -1e252;
      REP(j,i)sm += l[j+1];
      REP(j,i)mx = max(mx, l[j+1]);
      maxlen1 = sm;
      minlen1 = max(0.0, mx-(sm-mx));
    }
    double maxlen2 = 0.0, minlen2 = 0.0;
    {
      double sm = 0.0, mx = -1e252;
      FOR(j,i,n+2)sm += l[j+1];
      FOR(j,i,n+2)mx = max(mx, l[j+1]);
      maxlen2 = sm;
      minlen2 = max(0.0, mx-(sm-mx));
    }
    double ans = 0.0;
    ans += calc(maxlen1, maxlen2, l[0]);
    ans -= calc(minlen1, maxlen2, l[0]);
    ans -= calc(maxlen1, minlen2, l[0]);
    ans += calc(minlen1, minlen2, l[0]);
    printf("%.9f\n",ans);
  }
  return 0;
}
0