输入 a, b, c
如果数字形成一个阶梯,输出“ STAIR”,如果数字形成一个峰值,输出“ PEAK”,否则输出“ NONE”(输出不带引号的字符串)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<bits/stdc++.h> usingnamespace std; typedeflonglong ll; constint N = 2e6 + 10; ll t; intmain(){ cin >> t; ll a, b ,c; while (t--) { cin >> a >> b >> c; if (a < b && b < c) { cout << "STAIR" << endl; } elseif (a < b && b > c) { cout << "PEAK" << endl; } else { cout << "NONE" << endl; } } return0; }
vector<longlong> generateBinaryDecimals(int n){ queue<longlong> q; q.push(1); // Start with 1 as the first binary decimal number vector<longlong> result;
while (!q.empty()) { longlong num = q.front(); q.pop();
// Check if the current number is less than or equal to n if (num <= n) { result.push_back(num);
// Generate the next numbers by appending 0 and 1 q.push(num * 10); q.push(num * 10 + 1); } }
return result; }
intmain(){ vector<ll> tmp = generateBinaryDecimals(100000); // for (auto it : tmp) { // cout << it << endl; // } cin >> t; // remove 1 tmp.erase(tmp.begin()); sort(tmp.begin(), tmp.end(), greater<ll>()); ll a, b, c; while (t--) { cin >> n; // then for (auto it: tmp) { while (n % it == 0) { n /= it; } } if (n == 1) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return0; }
usingnamespace std; typedeflonglong ll; constint N = 2e6 + 10; ll t, n; #define debug(x) cout << #x << " = " << x << endl boolcheck(string s, int mid){ // check if have a substring of length mid int n = s.size(); unordered_map<string, int> mp; for (int i = 0; i <= n - mid; i+=mid) { string sub = s.substr(i, mid); mp[sub]++; if (mp.size() > 2) { returnfalse; } }
if (mp.size() == 1) { returntrue; } if (mp.size() == 2) { // must have one value == 1 bool f1 = 0; string s11 = ""; int c = 0; for (auto it : mp) { if (it.second == 1) { f1 = 1; } if (s11 == "") { s11 = it.first; } else { for (int i = 0; i < s11.size(); i++) { if (s11[i] != it.first[i]) { c++; } } } } if (f1 && c <= 1) { returntrue; } else { returnfalse; } } returnfalse; }
intmain(){
ll a, b ,c; cin >> t; while (t--) { string s; cin >> n; cin >> s; // a string len n // find min len of string k // find the number n % k == 0 vector<int> v; for (int i = 1; i <= n; i++) { if (n % i == 0) { v.push_back(i); } } ll ans = n; for (auto it : v) { if (check(s, it)) { ans = it; break; } } cout << ans << endl;
} return0; }
F. 0, 1, 2, Tree!(补题)
给点a, b, c 个度分别为 2,1,0 的节点,构建深度最小的树
思路:
先通过 a 和 c 构造完全二叉树,然后其中可以插入任意 b,所以有a + 1 != c(不能构成完全二叉树) 就是-1
ll a, b, c; cin >> t; while (t--) { cin >> a >> b >> c; // tree min height // a node have 2 son // b node have 1 son // c node have 0 son // a b c <= 10^5 // a + b + c = 3 * 10^5
ll tmp = 0; memset(v, 0, sizeof v); if (a + 1 != c) { cout << -1 << endl; continue; } else { v[0] = 1; ll h = 0; int l = a + b + c; for (int i = 1; i <= l; i++) { if (!v[h]) { h++; } v[h]--; if (a) { a--; v[h + 1] += 2; } elseif(b) { b--; v[h + 1]++; } elseif(c) { c--; } } cout << h << endl; } } return0; }