Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include<random>
- #include<cmath>
- constexpr int gen_n=210;
- constexpr int init_a=20;
- constexpr int init_b=0;
- int main() {
- int dog_a=init_a,dog_b=init_b;
- for (int i = 0; i < gen_n; ++i) {
- std::random_device rd;
- std::default_random_engine engine(rd());
- std::uniform_int_distribution<int> dist(1,gen_n+1);
- double pro_a=(double)std::abs(dog_a-dist(engine))/(double)gen_n;
- double pro_b=(double)std::abs(dog_b-dist(engine))/(double)gen_n;
- if(pro_a>pro_b&&dog_b>0){
- dog_a++;
- dog_b--;
- }else if(pro_a<pro_b&&dog_a>0){
- dog_a--;
- dog_b++;
- }
- if(dog_a==init_a&&dog_b==init_b){
- std::printf("Initial State number of generations:%d",i);
- break;
- }
- std::printf("x(%d)=(%d,%d)\n",i,dog_a,dog_b);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement