Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <set>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <fstream>
- #include <ctime>
- using namespace std;
- #define TASK "path"
- #define ll long long
- ll to_dm(string &s) {
- ll k = 1;
- ll ans = 0;
- for (int i = s.size() - 1; i >= 0; i--) {
- ans = ans + (s[i] - '0') * k;
- k = k * 2;
- }
- return ans;
- }
- int main() {
- srand(time(0));
- #ifdef _DEBUG
- //freopen("debug.in", "r", stdin);
- //freopen("debug.out", "w", stdout);
- #else
- //freopen(TASK".in", "r", stdin);
- //freopen(TASK".out", "w", stdout);
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- #endif // _DEBUG
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout.precision(6);
- ofstream fout;
- for (int i = 2; i < 100; i++) {
- string filename = "";
- filename += (i < 10 ? '0' : char(i / 10 + '0'));
- filename += char(i % 10 + '0');
- fout.open(filename + ".tst");
- int n, k;
- if (i >= 80) {
- n = rand() % 900000000 + 100000000, k = 10;
- }
- else {
- n = rand() % 999999999 + 1, k = rand() % 10 + 1;
- }
- fout << n << " " << k;
- fout.close();
- fout.open(filename + ".ans");
- string s = "";
- for (int i = 0; i < k; i++) {
- s += '1';
- }
- for (int i = k; i < 30; i++) {
- s += '0';
- }
- reverse(s.begin(), s.end());
- vector<int>ans;
- do {
- ll k = to_dm(s);
- if (k <= n)
- ans.push_back(k);
- else
- break;
- } while (next_permutation(s.begin(), s.end()));
- fout << ans.size() << endl;
- for (int i = 0; i < ans.size() && i < 1000; i++) {
- fout << ans[i] << endl;
- }
- fout.close();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment