Created
August 3, 2021 20:22
-
-
Save Philmist/f85d92f92cee7e151fb373508f8eea7f to your computer and use it in GitHub Desktop.
ガチャシミュテスト
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
cmake_minimum_required(VERSION 3.1) | |
project(gacha_yen_simulate) | |
find_package(OpenMP REQUIRED) | |
add_executable(gacha main.cpp) | |
target_link_libraries(gacha OpenMP::OpenMP_CXX) | |
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 long int max_yen = 0; | |
unsigned int gacha_times = 0; | |
unsigned int get_number = 0; | |
unsigned int tenjo_times = 0; | |
unsigned int goal = 1; | |
}; | |
int main() { | |
constexpr size_t LEN = 100000; | |
constexpr double PROB = 0.005; | |
constexpr unsigned long int MAX_YEN = 100000; | |
constexpr unsigned int PRICE = 300; | |
std::vector<Person> num(LEN); | |
assert(PROB > 0); | |
assert(PROB <= 1); | |
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) { | |
num[i].get_number += 1; | |
break; | |
} | |
if ((num[i].gacha_times * PRICE) >= num[i].max_yen) { | |
break; | |
} | |
} | |
} | |
std::cout << std::endl; | |
std::sort(num.begin(), num.end(), [](const Person& lt, const Person& rt){ return lt.gacha_times < rt.gacha_times; }); | |
double median; | |
double mean; | |
if ((std::round(LEN/2.0)*2) == LEN) { | |
median = (num[LEN/2].gacha_times + num[LEN/2+1].gacha_times) / 2.0; | |
} else { | |
median = num[static_cast<unsigned int>(std::round(LEN/2.0)+1)].gacha_times; | |
} | |
{ | |
unsigned long int total = 0; | |
for (const auto& i: num) { | |
total += i.gacha_times; | |
} | |
mean = static_cast<double>(total) / LEN; | |
} | |
auto over_s = std::count_if(num.begin(), num.end(), [&](const Person& v){ return v.gacha_times * PRICE >= v.max_yen; }); | |
std::cout << "SIZE:" << num.size() << std::endl; | |
std::cout << "MEDIAN TIMES:" << median << " YEN:" << median * PRICE << std::endl; | |
std::cout << "MEAN TIMES:" << mean << " YEN:" << mean * PRICE << std::endl; | |
std::cout << "MIN TIMES:" << num.begin()->gacha_times << " YEN:" << num.begin()->gacha_times * PRICE << std::endl; | |
std::cout << "MAX TIMES:" << (--num.end())->gacha_times << " YEN:" << (--num.end())->gacha_times * PRICE << std::endl; | |
std::cout << "OVER: " << over_s << std::endl; | |
std::cout << std::endl; | |
return 0; | |
} |
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
> (Measure-Command { .\Debug\gacha.exe | Write-Host }).TotalSeconds | |
SIZE:100000 | |
MEDIAN TIMES:138 YEN:41400 | |
MEAN TIMES:161.513 YEN:48454 | |
MIN TIMES:1 YEN:300 | |
MAX TIMES:334 YEN:100200 | |
OVER: 18746 | |
0.8822166 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment