Codeforces Round 957 (Div. 3)

 

题目链接:

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;
}

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值