#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
intmain() { random_device rd; auto now = chrono::system_clock::now().time_since_epoch().count(); mt19937_64 gen(rd() ^ now); uniform_int_distribution<ll> dist(1, 100); int n = dist(gen); cout << n << '\n'; for(int i = 1; i <= n; i++){ int x = dist(gen); cout << x << ' '; } cout << '\n'; return0; }
这里核心就是
1 2 3 4 5
random_device rd; auto now = chrono::system_clock::now().time_since_epoch().count(); mt19937_64 gen(rd() ^ now); uniform_int_distribution<ll> dist(1, 100); int n = dist(gen);
random_device rd提供一种初始种子
mt19937_64 gen(rd()); mt19937_64 gen是一个随机数生成器
正常来说这样就可以生成随机数了,但在devc++中因为编译器版本问题无法实现随机数
这时就要auto now = chrono::system_clock::now().time_since_epoch().count();来帮忙了
intmain() { ios::sync_with_stdio(0); cin.tie(0); int a, b; cin >> a >> b; if(a % 2 && b % 2)cout << a + b + 1 << '\n'; else cout << a + b << '\n'; return0; }
ac
1 2 3 4 5 6 7 8 9 10 11 12
#include<bits/stdc++.h> usingnamespace std;
intmain() { ios::sync_with_stdio(0); cin.tie(0); int a, b; cin >> a >> b; cout << a + b << '\n'; return0; }
data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
intmain() { random_device rd; auto now = chrono::system_clock::now().time_since_epoch().count(); mt19937_64 gen(rd() ^ now); uniform_int_distribution<ll> dist(1, 100); //cout << 1 << '\n'; // 如果有多测的话 int n = dist(gen); int m = dist(gen); cout << n << ' ' << m << '\n'; return0; }