Skip to content

Instantly share code, notes, and snippets.

@RoachLin
Created February 18, 2024 12:14
Show Gist options
  • Select an option

  • Save RoachLin/f5bc7e1bbbd520a8cd0329127e8f3aed to your computer and use it in GitHub Desktop.

Select an option

Save RoachLin/f5bc7e1bbbd520a8cd0329127e8f3aed to your computer and use it in GitHub Desktop.
偶像生写真和CD内封抽包概率近似计算
#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <random>
using namespace std;
int main()
{
const int pose = 3; // 3
const int member = 12;
const int photo = 5; // 5
const int package = 10;
const int times = 100 * 10000;
int set = 0;
random_device seeder;
uniform_int_distribution<int> distribution{1, member * pose};
array<int, package * photo> values{};
for (int i = 0; i < times; ++i)
{
const auto seed{seeder.entropy() ? seeder() : time(nullptr)};
mt19937 engine{static_cast<mt19937::result_type>(seed)};
auto generator{bind(distribution, engine)};
ranges::generate(values, generator);
if (ranges::any_of(values,
[](int v)
{
return v == 1;
}))
{
if (ranges::any_of(values,
[](int v)
{
return v == 2;
}))
{
if (ranges::any_of(values,
[](int v)
{
return v == 3;
}))
{
++set;
}
}
}
/*
if (ranges::any_of(values,
[](int v)
{
return v == 1;
}))
{
++set;
}
*/
/*
for (auto v : values)
{
cout << v << " ";
}
cout << endl;
*/
}
cout << set << endl;
cout << (double)set / (double)times << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment