#include<bits/stdc++.h> #define int long long usingnamespace std;
inlineintread(){ int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); } return x * f; }
voidsolve(){ int n = read(), k = read(); vector<int>v(k); for(auto &i : v) i = read(); sort(v.begin(), v.end()); int res = 0; for(int i = 0; i < k - 1; i++){ res += v[i] + v[i] - 1; } cout << res << '\n'; }
signedmain(){ int t = read(); while(t--) solve(); return0; }
C. Gorilla and Permutation
分析:构造题,给 >= k 的数分配尽可能大的权重,放在序列开头部分(降序), <= m 的数分配尽可能小的权重,放在序列尾端部分(升序)
#include<bits/stdc++.h> #define int long long usingnamespace std;
inlineintread(){ int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); } return x * f; }
voidsolve(){ int n = read(), m = read(), k = read(); int mid = min(k - 1, m); for(int i = n; i > mid; i--){ cout << i << ' '; } for(int i = 1; i <= mid; i++){ cout << i << ' '; } puts(""); }
signedmain(){ int t = read(); while(t--) solve(); return0; }
#include<bits/stdc++.h> #define int long long usingnamespace std;
inlineintread(){ int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); } return x * f; }
voidsolve(){ int n = read(), m = read(), k = read(); string s; cin >> s; s = "L" + s;
int cntw = 0; for (int i = 0; i <= n;) { int ok = 0; for (int j = m; j > 0; j--) { if (s[i + j] == 'L') { i += j; ok = 1; break; } } if (i + m >= n + 1) { cout << "YES" << '\n'; return; }
if (!ok) { for (int j = m; j > 0; j--) { if (s[i + j] == 'W') { i += j; ok = 2; break; } } }
#include<bits/stdc++.h> #define int long long usingnamespace std;
inlineintread(){ int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); } return x * f; }
intget(string& str, int len){ int x = 0; for (int i = 0; i < len; i++) { x = x * 10 + str[i] - 48; } return x; }
voidsolve(){ int n = read(); int cnt = 0; vector<pair<int, int>> ans; string s = to_string(n); string str = ""; for (int a = 1; a <= 10000; a++) { str += s;
int len = str.length(); int maxb = min({ (longlong)10000, a * n, len - 1 }); for (int b = max((longlong)1, len - 10); b <= maxb; b++) { if (get(str, len - b) == a * n - b) { cnt++; ans.emplace_back(a, b); } } } cout << cnt << '\n'; for(auto [a, b] : ans){ cout << a << ' ' << b << '\n'; } }
signedmain(){ int t = read(); while(t--) solve(); return0; }