题意:略。ios
分析:略。c++
#include <bits/stdc++.h> #define rep(i, a, b) for (long long i = a; i <= b; ++i) #define mp make_pair #define ll long long #define SIZE 1005 using namespace std; void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } int n, m, k; int main() { io(); cin >> n >> m >> k; swap(n, m); swap(n, k); cout << n << ' ' << m << ' ' << k; }
题意:略。spa
分析:略。code
#include <bits/stdc++.h> #define rep(i, a, b) for (long long i = a; i <= b; ++i) #define mp make_pair #define ll long long #define SIZE 1005 using namespace std; void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } int n, m, k; int main() { io(); cin >> n >> m; vector<double> a(n); double sum = 0; for (auto& i : a) cin >> i, sum += i; sum /= (4.0 * m); sort(a.begin(), a.end()); reverse(a.begin(), a.end()); rep(i, 0, (m - 1)) { if (a[i] < sum) { cout << "No"; return 0; } } cout << "Yes"; }
题意:给定两个正整数 \(N,K\) ,你可以进行如下操做无限次:将 \(N\) 替换为 \(|N-K|\) 。询问全部操做中 \(N\) 的最小值。ci
分析:随便推导一下不难发现最小值只能是 \(min(K\%N,K-K\%N)\) 。字符串
#include <bits/stdc++.h> #define rep(i, a, b) for (long long i = a; i <= b; ++i) #define mp make_pair #define ll long long #define SIZE 1005 using namespace std; void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } ll k, n; int main() { io(); cin >> n >> k; cout << min(n % k, k - n % k); }
题意:定义 \(Lunlun\ Number\) 是指相邻每两位数字之差不超过 \(1\) 的数字,求第 \(k\) 大的 \(Lunlun\ Number\) 。string
分析:假设某个 \(Lunlun\ Number\) 的末尾是 \(k\) ,那么由它可以引出的下一个 \(Lunlun\ Number\) 只能是在末尾加上 \(k-1,k,k+1\) 这三种状况(注意特判 \(k=0,9\) 的状况)。而后用这个性质 \(BFS\) 便可。hash
#include <bits/stdc++.h> #define rep(i, a, b) for (long long i = a; i <= b; ++i) #define mp make_pair #define ll long long #define SIZE 1005 using namespace std; void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } ll k; set<string> st; int main() { io(); cin >> k; queue<string> q; rep(i, 1, 9) q.push(to_string(i)); vector<ll> vec; while (st.size() <= 2e5) { string top = q.front(); q.pop(); st.insert(top); if (top.back() != '9' && top.back() != '0') { char ch = top.back(); --ch; q.push(top + ch); q.push(top + top.back()); ch += 2; q.push(top + ch); } else if (top.back() == '0') { char ch = top.back(); ++ch; q.push(top + top.back()); q.push(top + ch); } else { char ch = top.back(); --ch; q.push(top + ch); q.push(top + top.back()); } } for (auto i : st) vec.emplace_back((ll)stoll(i)); sort(vec.begin(), vec.end()); cout << vec[k - 1]; }
题意:\(Takahashi\) 在总共 \(N\) 天里一共要选择 \(K\) 个工做日,可是他每工做一天就要休息 \(C\) 天。给定一个由 \(x,o\) 构成的字符串,若 \(s_i=x\) 就表明第 \(i\) 天不能工做,询问哪几天是 \(Takahashi\) 没得选择,必须工做的。it
分析:先考虑 \(Takahashi\) 在什么状况下不存在没法选择的状况,显然是贪心时至少存在 \(K+1\) 个可选工做日。所以,咱们只须要考虑在贪心的状况下只存在 \(K\) 个工做日时,这 \(K\) 个工做日的分布,极端地考虑,咱们正反贪心两次若是两次都须要工做的日子就一定是 \(Takahashi\) 的工做日了。io
#include <bits/stdc++.h> #define rep(i, a, b) for (long long i = a; i <= b; ++i) #define mp make_pair #define ll long long #define SIZE 1005 using namespace std; void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } ll n, k, c; int main() { io(); cin >> n >> k >> c; string s; cin >> s; int pos = -1, res = 0; set<int> st, st2; rep(i, 0, (s.length() - 1)) { if (pos >= i || s[i] == 'x') continue; if (st.size() == k) { ++res; break; } pos = i + c; st.insert(i); } if (res) return 0; pos = s.length(); for (int i = s.length() - 1; i >= 0; --i) { if (pos <= i || s[i] == 'x') continue; if (st2.size() == k) { ++res; break; } pos = i - c; if (st.count(i)) st2.insert(i); } if (res) return 0; for (auto i : st2) cout << i + 1 << '\n'; }
题意:给定一个正整数 \(N\) ,而后你能够选择一个正整数 \(K\) 并执行如下两种操做:
询问能将 \(N\) 转化为 \(1\) 的正整数 \(K\) 的数量。
分析:分红两部分考虑:一是 \(N\) 直接减去 \(N-1\) ,这种状况下的 \(K\) 就是 \(N-1\) 的全部因子;二是除了状况一之外的全部状况(就是须要考虑操做 \(1\) 的状况,状况一咱们只考虑了操做 \(2\) ),这些状况下的 \(K\) 不难发现一定是 \(N\) 的因子,所以咱们取出全部 \(N\) 的因子模拟便可。
这两种状况不存在相同的因子,由于相邻天然数互质。
#include <bits/stdc++.h> #define rep(i, a, b) for (long long i = a; i <= b; ++i) #define mp make_pair #define SIZE 2010 #define ll long long using namespace std; void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } ll n; int main() { io(); cin >> n; int ans = 1; for (ll i = 2; i * i <= n; ++i) { if (n % i == 0) { ll tmp = n; while (tmp % i == 0) tmp /= i; if ((tmp - 1) % i == 0) ans++; tmp = n; if (i * i == n) continue; ll x = n / i; while (tmp % x == 0) tmp /= x; if ((tmp - 1) % x == 0) ans++; } } if (--n > 1) ++ans; for (ll i = 2; i * i <= n; ++i) { if (n % i == 0) { ans += 2; if (i * i == n) --ans; } } cout << ans; }