Created
September 9, 2021 11:13
-
-
Save Philmist/44cd9dcbcc17ba4d174898e0bff92d90 to your computer and use it in GitHub Desktop.
ガチャガチャ1天井まで回す
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 <iostream> | |
#include <random> | |
#include <algorithm> | |
#include <cmath> | |
#include <cassert> | |
#include <utility> | |
#include <vector> | |
#include <omp.h> | |
struct Person { | |
unsigned int rice = 0; | |
unsigned int kashimoto = 0; | |
unsigned int gacha_times = 0; | |
}; | |
int main() { | |
constexpr size_t LEN = 1000000; | |
constexpr double PROB_KASHIMOTO = 0.0075; | |
constexpr double PROB_RICE = 0.0075; | |
constexpr unsigned int GOAL = 5; | |
constexpr unsigned int TENJO = 200; | |
std::vector<Person> num(LEN); | |
/* | |
for (auto& it: num) { | |
it.max_yen = MAX_YEN; | |
} | |
*/ | |
std::random_device seed_gen; | |
std::mt19937_64 random_engine(seed_gen()); | |
std::uniform_real_distribution<> rand; | |
#pragma omp parallel for | |
for (long int i=0;i<num.size();i++) { | |
while(true) { | |
num[i].gacha_times += 1; | |
auto gacha = rand(random_engine); | |
if (gacha <= (PROB_KASHIMOTO + PROB_RICE)) { | |
auto card = rand(random_engine); | |
if (card > 0.5) { | |
num[i].rice += 1; | |
} else { | |
num[i].kashimoto += 1; | |
} | |
} | |
if (num[i].rice >= GOAL && num[i].kashimoto >= GOAL) { | |
break; | |
} | |
if (num[i].gacha_times >= TENJO) { | |
num[i].rice += num[i].rice > num[i].kashimoto ? 0 : 1; | |
num[i].kashimoto += num[i].kashimoto > num[i].rice ? 0 : 1; | |
break; | |
} | |
} | |
} | |
std::cout << std::endl; | |
std::sort(num.begin(), num.end(), [](const Person& lt, const Person& rt){ return lt.gacha_times < rt.gacha_times; }); | |
auto over_s = std::count_if(num.begin(), num.end(), [&](const Person& v){ return v.kashimoto >= GOAL && v.rice >= GOAL; }); | |
std::cout << "TOTAL PROB: " << PROB_KASHIMOTO << " : " << PROB_RICE << " : " << (PROB_KASHIMOTO + PROB_RICE) << std::endl; | |
std::cout << "SIZE: " << num.size() << std::endl; | |
std::cout << "REACH: " << over_s << std::endl; | |
std::cout << "PROB: " << ((double)over_s / (double)num.size()) << std::endl; | |
std::cout << "[0]: " << num[0].kashimoto << " : " << num[0].rice << " : " << num[0].gacha_times << std::endl; | |
std::cout << "[-1]: " << num[LEN-1].kashimoto << " : " << num[LEN-1].rice << " : " << num[LEN-1].gacha_times << std::endl; | |
std::cout << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment