結果

問題 No.352 カード並べ
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2016-03-10 22:34:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,565 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 92,608 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 22:33:56
合計ジャッジ時間 2,855 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,372 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000007

unsigned int xor128(void) { 
  static unsigned int x = 123456789;
  static unsigned int y = 362436069;
  static unsigned int z = 521288629;
  static unsigned int w = 88675123; 
  unsigned int t;
 
  t = x ^ (x << 11);
  x = y; y = z; z = w;
  return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); 
}

// モンテカルロ法のテスト

int main(){
  int n;
  cin>>n;
  double a = 0.;
  rep(b,0,100000){
    double ans = 1.;
    vector<int> v;
    v.pb(1);
    rep(i,2,n+1){
      int p = xor128()%i;
      if(p==0){
        vector<int> v1;
        v1.pb(i);
        rep(j,0,v.sz)v1.pb(v[j]);
        ans += 1.;
        v = v1;
      }
      else if(p == i-1){
        v.pb(i);
        ans += 1.;
      }
      else{
        vector<int> v1;
        rep(j,0,p)v1.pb(v[j]);
        v1.pb(i);
        rep(j,p,v.sz)v1.pb(v[j]);
        ans += 1.*v[p-1]*v[p];
        v = v1;
      }
    }  
    a += ans;
  }
  printf("%20.20f\n",a/100000);
  return 0;
}
0