Skip to content

Instantly share code, notes, and snippets.

@RoachLin
Created March 26, 2024 06:30
Show Gist options
  • Select an option

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

Select an option

Save RoachLin/14250dec126b44e0f0d53f99e026b41c to your computer and use it in GitHub Desktop.
偶像生写真和CD内封抽包概率近似计算_v2
#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 = 40;
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);
bool flag = true;
for (int j = 1; j <= member * pose; ++j)
{
if (ranges::any_of(values,
[j](int v)
{
return v == j;
}))
{
continue;
}
else
{
flag = false;
break;
}
}
if (flag == true)
{
++set;
}
/*
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;
}
/*
抽包:
1*5
71430
0.00118132
6s
1*6
4930740
0.00226515
272s
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment