結果

問題 No.620 ぐるぐるぐるりん
ユーザー rickythetarickytheta
提出日時 2017-12-20 11:34:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 1,000 ms
コード長 2,575 bytes
コンパイル時間 2,600 ms
コンパイル使用メモリ 147,608 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 21:25:19
合計ジャッジ時間 3,573 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl

#define double long double

int t;
double p;
double omega, v;
double gx, gy;

int m;
double B[2][35];
double b[35];
double A[2][2];
double Ainv[2][2];
double xy[2];
double z[35];

void solve(){
  scanf("%d%Lf%Lf%Lf%Lf%Lf",&t,&p,&omega,&v,&gx,&gy);
  vector<double> vx, vy;
  REP(i,t){
    double x = 1.0, y = 0.0;
    FOR(j,i+1,t){
      double nx = x - omega*y + v*x;
      double ny = y + omega*x + v*y;
      x = nx;
      y = ny;
    }
    vx.push_back(x);
    vy.push_back(y);
    x = 0.0, y = 1.0;
    FOR(j,i+1,t){
      double nx = x - omega*y + v*x;
      double ny = y + omega*x + v*y;
      x = nx;
      y = ny;
    }
    vx.push_back(x);
    vy.push_back(y);
  }
  double sx = 1.0, sy = 0.0;
  REP(i,t){
    double nx = sx - omega*sy + v*sx;
    double ny = sy + omega*sx + v*sy;
    sx = nx;
    sy = ny;
  }
  double ax = gx-sx, ay = gy-sy;

  // problem. sum p_i vx_i == ax
  //          sum p_i vy_i == ay
  //          sum p_i^2    <= p
  // minimize. sum p_i^2
  // subject to. sum p_i vx_i == ax
  //             sum p_i vy_i == ay
  m = 2*t;
  // Bx = b
  REP(i,2)REP(j,m)B[i][j] = 0.0;
  REP(i,m)B[0][i] = vx[i];
  REP(i,m)B[1][i] = vy[i];
  b[0] = ax;
  b[1] = ay;
  // A = BB^T
  REP(i,2)REP(j,2)A[i][j] = 0.0;
  REP(i,2)REP(j,2)REP(k,m)A[i][j] += B[i][k] * B[j][k];
  // Ay = b
  double detA = A[0][0] * A[1][1] - A[0][1] * A[1][0];
  Ainv[0][0] = A[1][1] / detA;
  Ainv[0][1] = -A[0][1] / detA;
  Ainv[1][0] = -A[1][0] / detA;
  Ainv[1][1] = A[0][0] / detA;
  // y = Ainv b
  xy[0] = Ainv[0][0] * b[0] + Ainv[0][1] * b[1];
  xy[1] = Ainv[1][0] * b[0] + Ainv[1][1] * b[1];
  // z = A^T y
  REP(i,m)z[i] = B[0][i] * xy[0] + B[1][i] * xy[1];

  // simulate
  double simx = 1.0, simy = 0.0;
  double power = 0.0;
  REP(i,t){
    double ux = z[2*i], uy = z[2*i+1];
    printf("%.40Lf %.40Lf\n", ux, uy);
    power += ux*ux + uy*uy;
    double nx = simx - omega*simy + v*simx + ux;
    double ny = simy + omega*simx + v*simy + uy;
    simx = nx;
    simy = ny;
  }
  // printf("(%.5f, %.5f) is goal, (%.5f, %.5f) is answer, power is %.5f(<= %.5f)\n", gx, gy, simx, simy, power, p);
}

int main(){
  int n;
  scanf("%d",&n);
  while(n--)solve();
  return 0;
}
0