#include <iostream>
#include <vector>
//#include <bitset>//サイズ指定がコンパイルタイムだったOrz あいたたたた・・・。
#include <random>
#include <algorithm>
std::vector<std::size_t> MakeRandom(std::size_t N){
std::vector<std::size_t> vec(N);
std::size_t i = 0;
for (auto& o : vec) o = i++;
std::random_device rd;
std::mt19937 mt(rd());
std::shuffle(vec.begin(), vec.end(), mt);
return vec;
}
std::pair<std::size_t, std::size_t> MakeHoge(std::size_t N,bool IsShowArray=false){
std::vector<bool> bvec(N);//vecter<bool>の実装は適当なのでちゃんとメモリ圧縮できてるか自信ない。
auto vec = MakeRandom(N);
std::size_t V[2] = { 0, 0 };
int C=0;
vec.pop_back();//ランダムから2つ落す。
vec.pop_back();
for (std::size_t i = 0; i < vec.size(); i++)
{
bvec[vec[i]] = true;
if (IsShowArray == true) std::cout << vec[i] << ',';
}
if (IsShowArray == true) std::cout << std::endl;
for (std::size_t i = 0; i < bvec.size(); i++)
{
if (bvec[i] == false) {
V[C] = i;
C++;
if (C == 2) break;
}
}
if (V[0]>V[1]) std::swap(V[0], V[1]);
return std::make_pair(V[0], V[1]);
}
int main(){
std::pair<std::size_t, std::size_t> P;
P = MakeHoge(16, true);
std::cout << "I find the " << P.first << " & " << P.second << "!!" << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgovLyNpbmNsdWRlIDxiaXRzZXQ+Ly/jgrXjgqTjgrrmjIflrprjgYzjgrPjg7Pjg5HjgqTjg6vjgr/jgqTjg6DjgaDjgaPjgZ9PcnrjgIDjgYLjgYTjgZ/jgZ/jgZ/jgZ/jg7vjg7vjg7vjgIIKI2luY2x1ZGUgPHJhbmRvbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCnN0ZDo6dmVjdG9yPHN0ZDo6c2l6ZV90PiBNYWtlUmFuZG9tKHN0ZDo6c2l6ZV90IE4pewoJc3RkOjp2ZWN0b3I8c3RkOjpzaXplX3Q+IHZlYyhOKTsKCXN0ZDo6c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