Created
February 18, 2024 12:14
-
-
Save RoachLin/f5bc7e1bbbd520a8cd0329127e8f3aed to your computer and use it in GitHub Desktop.
偶像生写真和CD内封抽包概率近似计算
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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