Submission #169864
Source Code Expand
Copy
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <set> #include <map> #include <string> #include <stack> #include <queue> #include <cmath> #include <cstdio> #include <istream> #include <sstream> #include <iomanip> #include <iterator> #include <climits> using namespace std; typedef ostringstream OSS; typedef istringstream ISS; typedef vector<int> VI; typedef vector< VI > VVI; typedef long long LL; typedef pair<int, int> PII; typedef vector<PII> VPII; #define X first #define Y second unsigned long xor128(unsigned long n){ static unsigned long x=time(NULL),y=362436069,z=521288629,w=88675123; unsigned long t; t=(x^(x<<11)); x=y; y=z; z=w; return w=((w^(w>>19))^(t^(t>>8)))%n; } int count_opens(VI &perm, VI &coins) { int opens = 0; int N = perm.size(); for (int i = 0; i < N; i++) { bool rev = true; for (int j = 0; j < i; j++) { rev = !(coins[perm[i]] % coins[perm[j]]) ^ rev; } opens += rev; } return opens; } int main(void) { int N; cin >> N; VI coins(N); for(auto &coin : coins) { cin >> coin; } VI perm(N); iota(perm.begin(), perm.end(), 0); int opens = 0; int loop; if (N <= 8) { loop = 0; do { opens += count_opens(perm, coins); loop++; } while(next_permutation(perm.begin(), perm.end())); }else { loop = 1e+5; for (int l = 0; l < loop; l++) { random_shuffle(perm.begin(), perm.end(), xor128); opens += count_opens(perm, coins); } } cout << ((double)opens / (double)loop) << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - コイン |
User | snakazawa |
Language | C++ (G++ 4.6.4) |
Score | 0 |
Code Size | 1621 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:62:12: error: ISO C++ forbids declaration of ‘coin’ with no type [-fpermissive] ./Main.cpp:62:19: error: range-based-for loops are not allowed in C++98 mode ./Main.cpp:67:34: error: ‘iota’ was not declared in this scope