题目链接:
https://codeforces.com/contest/1992
A
代码:
void solve() {
int a, b, c;
cin >> a >> b >> c;
int maxx = -inf;
for (int i = 0; i <= 5; ++i) {
for (int j = 0; j <= 5; ++j) {
if (i + j > 5) continue;
maxx = max(maxx, (a + i) * (b + j) * (c + (5 - i - j)));
}
}
cout << maxx << "\n";
}
B
代码
void solve() {
int m, n;
cin >> m >> n;
vector<int>a(n + 1);
int cnt = 0;
int maxx = -1,idx=-1;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (a[i] > maxx) {
maxx = a[i];
idx = i;
}
}
int res = m - maxx;
for (int i = 1; i <= n; ++i) {
if (i == idx) continue;
res += a[i] - 1;
}
cout << res << "\n";
}
C
代码:
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<int>res1,res2,res3;
for (int i = 1; i <= n; ++i) {
if (i >m) {
res1.emplace_back(i);
}
else if(i<=k){
res3.push_back(i);
}
else {
res2.emplace_back(i);
}
}
sort(res1.begin(), res1.end(), greater<int>());
sort(res3.begin(), res3.end());
for (auto& x : res1) cout << x << " ";
for (auto& x : res2) cout << x << " ";
for (auto& x : res3) cout << x << " ";
cout << "\n";
}
D
代码:
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<char>a(n + 2);
set<int>pos;//鳄鱼的位置
vector<int>dp(n + 2, inf); //代价
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (a[i] == 'C') {
pos.insert(i);
}
}
a[0] = 'L';
a[n + 1] = 'L';
dp[0] = 0;
for (int i = 1; i <= n + 1; ++i) {
bool flag = false;
for (int j = 1; j <= m; ++j) {
if (i - j < 0) continue;
if (a[i - j] == 'L') {
if (a[i] == 'W') {
dp[i] = min(dp[i], dp[i - j] + 1);
}
else if (a[i] == 'L') {
dp[i] = min(dp[i], dp[i - j]);
}
else {
dp[i] = inf;
}
flag = true;
}
else if (a[i - j] == 'W') {
bool ok = true;
if (a[i] == 'W') {
for (int k = i - j + 1; k <= i - 1; ++k) {
if (pos.count(k)) {
ok = false;
break;
}
}
if (ok) {
flag = true;
dp[i] = min(dp[i], dp[i - j] + j);
}
}
else if (a[i] == 'L') {
bool ok = true;
for (int k = i - j + 1; k <= i - 1; ++k) {
if (pos.count(k)) {
ok = false;
break;
}
}
if (ok) {
flag = true;
dp[i] = min(dp[i], dp[i - j] + j - 1);
}
}
else {
dp[i] = inf;
}
}
}
if (!flag) {
cout << "NO\n";
return;
}
}
//debug(dp, "dp");
cout << (dp[n + 1] > k ? "NO" : "YES") << "\n";
}
E
代码:
inline int get_len(int x) {
int len = 0;
while (x) {
x /= 10;
len++;
}
return max(len, 1);
}
void solve() {
int n;
cin >> n;
vector<pii>res;
auto check = [](pii w,int x,int b) ->int {
//计算w "-" b == x - b 是否成立
int a = w.first, n = w.second;
int len_x_b = get_len(x - b);
int len = a * get_len(n) - b - len_x_b;//长度
if (len < 0) { //b 太大了
return 1;
}
else if (len > 0) {//b太小了
return 2;
}
else { //==0的情况
int m = len_x_b; //不超过9位
string n_str = to_string(n);
int k = n_str.size();
int num = 0;
string t;
//获取w "-" b
for (int i = 0; i < m; ++i) {
t += (n_str[i % k]);
}
return stoi(t) == (x - b) ? 3 : -1;
}
};
for (int a = 1; a <= 10000; ++a) { //枚举a
//记 w = "n"*a
pii w = { a,n };
int x = n * a;
//二分b,判断是否 w "-" b == x - b
int l = 1, r = min(10000, a * n);
while (l <= r) {
int mid = l + r >> 1;
int k = check(w, x, mid);
if (k==-1){
break;
}
else if(k==1) {
r = mid - 1;
}
else if (k == 2) {
l = mid + 1;
}
else if (k == 3) {
res.emplace_back(a, mid);
break;
}
}
}
cout << res.size() << "\n";
for (auto& x : res) {
cout << x.first << " " << x.second << "\n";
}
F
代码:
void solve() {
int n, x;
cin >> n >> x;
vector<int>a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
map<int, int>mp;
for (int i = 2; i <= sqrt(x); ++i) {
if (x % i == 0) {
int y = x;
while (y % i == 0) {
y /= i;
mp[i]++;
}
y = x;
while (y % (x / i) == 0) {
y /= (x / i);
mp[x / i]++;
}
}
}
map<int, int>mp2 = mp;
int res = 1;
set<int>st;
for (int i = 1; i <= n; ++i) {
if (x % a[i] == 0 && mp[a[i]] > 0) {
mp[a[i]]--;
vector<int>tmp;
for (auto& t : st) {
if (x % (t * a[i]) == 0) {
tmp.push_back(t * a[i]);
}
}
st.insert(a[i]);
for (auto& x : tmp) {
st.insert(x);
}
if (st.count(x)) {
++res;
st.clear();
st.insert(a[i]);
mp = mp2;
mp[a[i]]--;
}
}
}
cout << res << "\n";
}
G
代码:
const int N = 1e6 + 10;
//=====组合数板子===============
namespace CNM
{
const int N = 3e5 + 5;
int quick(int x, int n){
x %= mod;
int res = 1;
while (n)
{
if (n & 1)
res = (res * x) % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
int inv(int x) { return quick(x, mod - 2); }
int fac[N], invfac[N];
void init()
{
fac[0] = 1;
for (int i = 1; i < N; ++i)
fac[i] = (fac[i - 1] * i) % mod;
invfac[N - 1] = inv(fac[N - 1]);
for (int i = N - 2; i >= 0; --i)
invfac[i] = (invfac[i + 1] * (i + 1)) % mod;
}
int C(int n, int m)
{
if (n < m || m < 0)
return 0;
return fac[n] * invfac[m] % mod * invfac[n - m] % mod;
}
}
using namespace CNM;
void solve()
{
int n;
cin >> n;
int ans = 1;
for (int i = 1; i <= n; i++)
{
if (i * 2 >= n)
{
ans += ((((2 * i + 1) % mod) * (C(n, i) % mod)) % mod);
ans %= mod;
}
else
{
for (int m = i + 1; m <= 2 * i + 1; m++)
{
ans += (((((C(m - 1, m - 1 - i) % mod) * (C(n - m, 2 * i + 1 - m) % mod)) % mod) * (m % mod)) % mod);
ans %= mod;
}
}
}
cout << ans << endl;
}
//main 函数
signed main() {
std::ios::sync_with_stdio(0);
std::cout.tie(0);
std::cin.tie(0);
int t = 1;
init();
cin >> t;
while (t--) {
solve();
}
return 0;
}