Codeforces Round 917 (Div. 2) A - C 题解

备注 :此题解的[]为数学中的集合表示。

A. Least Product

题意:一共有n个数字,想要求最小的乘积。可以做任意次操作,如果a[i]是负数,可以将此数修改成[a[i] , 0]。如果a[i]是正数,可以将此数修改成[0 , a[i]] 。
题解:如果没有负数,那么最小的数字是将一个数字修改成0。如果有零,那么直接输出0,。如果有负数,是偶数的话,将随便一个数字改成0。是奇数的话,直接输出0即可。

代码:

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 4e5 + 7 ;
inline ll read(){
	ll x = 0 , f = 1 ;
	char c = getchar() ;
	while(c > '9' || c < '0'){
		if(c == '-')
			f = -1 ;
		c = getchar() ;
	}
	while(c >= '0' && c <= '9'){
		x = x * 10 + c - '0' ;
		c = getchar() ;
	}
	return x * f ;
}
char s[maxn] , S[maxn] ;
ll t , n , k , q , a[maxn] , c[maxn] ;
bool vis[maxn] ;
ll b[maxn] , d[maxn] ;
void solve(){
	n = read() ;
	for(int i = 1 ; i <= n ; i ++){
		a[i] = read() ;
	}
	int fu = 0 , zheng = 0 ;
	for(int i = 1 ; i <= n ; i ++){
		if(a[i] == 0){
			cout << 0 << endl ;
			return ;
		}
		if(a[i] < 0){
			fu ++ ;
		}
		if(a[i] > 0){
			zheng ++ ;
		}
	}
	if(fu == 0){
		cout << 1 <<endl ;
		cout << 1 << " " << 0 << endl ;
		return ;
	}
	if(fu %2 == 1){
		cout << 0 << endl ;
		return ;
	}
	else{
		for(int i = 1 ; i <= n ; i ++){
			if(a[i] < 0){
				cout << 1 << endl ;
				cout << i << " " << 0 << endl ; 
				return ;
			}
		}
	}
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

B. Erase First or Second Letter

题意:给你一个字符串,每次可以删去一个数字,可以选择删第一个数组或者第二个数字。问一共可以构成多少个非空的不同字符串。
题解:这明显是一道逻辑思维题,很容易得出规律,每个字符串新出现贡献1,重复出现没有贡献,累加即可。

代码:

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 4e5 + 7 ;
inline ll read(){
	ll x = 0 , f = 1 ;
	char c = getchar() ;
	while(c > '9' || c < '0'){
		if(c == '-')
			f = -1 ;
		c = getchar() ;
	}
	while(c >= '0' && c <= '9'){
		x = x * 10 + c - '0' ;
		c = getchar() ;
	}
	return x * f ;
}
char s[maxn] , S[maxn] ;
ll t , n , k , q , a[maxn] , c[maxn] ;
bool vis[maxn] ;
ll b[maxn] , d[maxn] ;
void solve(){
	n = read() ;
	scanf("%s" , s + 1) ;
	map < ll , ll > mp ;
	ll cnt = 0 , ans = 0 ;
	for(int i = 1 ; i <= n ; i ++){
		int res = s[i] - 'a' ;
		if(mp[res] == 0){
			cnt ++ ;
			mp[res] = 1 ;
		}
		ans += cnt ;
	}
	cout << ans << endl ;
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

C. Watering an Array

题意:给你n个数字a和k个数字b还有一个d,有两个操作,一个是将a[i]的[1,b[i % k]]加上1,第二个操作是统计(a[i] == i)的个数,添加到答案里。每次必须选一个操作操作,问最大的答案是多少。
题解:因为他第二个操作的统计答案一定是递增的才会增加更多的答案,但是第一个操作会使数列变成递减的,所以多次选择一操作再统计答案没有选一次一操作统计一次答案更优。那么问题就转化为原始数列加上n次b[i],如何使答案更优,因为一次操作可以增加[1 , n] ,所以大胆猜测最多操作2 * n 次。那么答案就是每次的(a[i] == i)的数量加上(d - (i + 1)) / 2的数量,求最大值即可。

代码:

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
inline ll read(){
	ll x = 0 , f = 1 ;
	char c = getchar() ;
	while(c > '9' || c < '0'){
		if(c == '-')
			f = -1 ;
		c = getchar() ;
	}
	while(c >= '0' && c <= '9'){
		x = x * 10 + c - '0' ;
		c = getchar() ;
	}
	return x * f ;
}
char s[maxn] , S[maxn] ;
ll t , n , k , q , a[maxn] , c[maxn] ;
bool vis[maxn] ;
ll b[maxn] , d[maxn] ;
void solve(){
	n = read() ;
	k = read() ;
	q = read() ;
	for(int i = 1 ; i <= n ; i ++){
		a[i] = read() ;
	}
	for(int i = 0 ; i < k ; i ++){
		b[i] = read() ;
	}
	ll ans = 0 ;
	for(int i = 0 ; i < 2 * n && (i + 1) <= q ; i ++){
		ll cnt = 0 ;
		for(int j = 1 ; j <= n ; j ++){
			if(a[j] == j){
				cnt ++ ;
			}
		}
		ans = max(ans , cnt + (q - (i + 1)) / 2) ;
		ll t = b[i % k] ;
		for(int j = 1 ; j <= t ; j ++){
			a[j] ++ ;
		}
	}
	cout << ans << endl ;
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

喜欢作者的记得点赞收藏加关注哦~~~

  • 21
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
抱歉,根据提供的引用内容,我无法理解你具体想要问什么问题。请提供更清晰明确的问题,我将竭诚为你解答。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【CodeforcesCodeforces Round 865 (Div. 2) (补赛)](https://blog.csdn.net/t_mod/article/details/130104033)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小许愿瓶

我的成长我做主

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值