Codeforces Round 933 (Div. 3) A - E题解

A. Rudolf and the Ticket

题意:问有多少组数字可以满足a_i + b_j <= k

题解:枚举统计答案即可。

代码:

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
const int mod = 998244353 ;
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 ;
}

ll t , n , d , k , m , b[maxn] , a[maxn] ;
void solve(){
	n = read() ;
	m = read() ;
	k = read() ;
	for(int i = 1 ; i <= n ; i ++){
		a[i] = read() ;
	}
	for(int i = 1 ; i <= m ; i ++){
		b[i] = read() ;
	}
	ll ans = 0 ;
	for(int i = 1 ; i <= n ; i ++){
		for(int j = 1 ; j <= m ; j ++){
			if(a[i] + b[j] <= k){
				ans ++ ;
			}
		}
	}
	cout << ans << endl ;
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

B. Rudolf and 121

题意:给你n个数字,有一个操作,会使a_i = a_i - 2,a_{i - 1} = a_{i - 1} - 1 , a_{i + 1} = a_{i + 1} - 1,看看能不能让所有数字变成0。
题解:最左边的数字在这一轮必须变成0,因为i从2往右走,只有一次机会让a_{i - 1}变成0,所以直接枚举,每次取min(a_i / 2 , a_{i - 1}),遍历一遍从2 - n - 1看看能否将数组全部变成0即可。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
const int mod = 998244353 ;
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 ;
}

ll t , n , d , k , m , b[maxn] , a[maxn] ;
void solve(){
	n = read() ;
	for(int i = 1 ; i <= n ; i ++){
		a[i] = read() ;
	}
	for(int i = 2 ; i <= n - 1 ; i ++){
		ll res = max(a[i - 1] , 0ll) ;
		a[i] -= res * 2 ;
		a[i - 1] -= res ;
		a[i + 1] -= res ;
	}
	for(int i = 1 ; i <= n ; i ++){
		if(a[i] != 0){
			cout << "NO\n" ;
			return ;
		}
	}
	cout << "YES\n" ;
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

C. Rudolf and the Ugly String

题意:有两个字符串,“pie”和“map”,问最少进行多少操作可以使字符串里不包含这两个字符串。
题解:看看样例,很容易发现不管是“pie”还是“map”,就拿“pie”做例子,有可能会有很多p也有可能有很多e,如果都去掉肯定不最优,那明显就去中间的字母,因为如果中间字母有很多个,那就组不成“pie”,“map”同理,只需要再想一个特殊的情况,如果字符串是“mapie”,那么只需要去掉p即可。所以直接枚举,判断累加答案即可。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
const int mod = 998244353 ;
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 ;
}

ll t , n , d , k , m , b[maxn] , a[maxn] ;
char s[maxn] ;
void solve(){
	n = read() ;
	scanf("%s" , s + 1) ;
	int rt = 1 ;
	ll ans = 0 ;
	while(1){
//		cout << rt << endl ;
		if(rt >= n){
			break ;
		}
		if(rt + 4 <= n){
			string ss = "" ;
			for(int i = rt ; i <= rt + 4 ; i ++){
				ss = ss + s[i] ;
			}
			if(ss == "mapie"){
				ans ++ ;
				rt = rt + 4 ;
				continue ;
			}
		}
		if(rt + 2 <= n){
			string ss = "" ;
			for(int i = rt ; i <= rt + 2 ; i ++){
				ss = ss + s[i] ;
			}
			if(ss == "map" || ss == "pie"){
				ans += 1 ;
				rt = rt + 2 ;
				continue ;
			}
		}
		rt ++ ;
	}
	cout << ans << endl ;
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

D. Rudolf and the Ball Game

题意:给你n个数,m次操作,开始的时候球在k的手里,有三种操作,第一种是“0”,让球顺时针传递x个人,第二种是“1”,让球逆时针传递x个人,第三种是“?”,不确定方向,可以顺时针传递也可以逆时针传递,问球最终可能在哪些人手上,按数字大小顺序输出。
题解:首先可以想到dfs搜索,很好处理,看到m的数据范围是1000,那明显不行,那就想到用数据结构或者STL来维护数字,一开始我觉得不太行,因为数据范围都是1000,那么乘起来肯定爆掉了,但是看到n * m <= 2e5,再想,就算是每个操作是“?” , 最多每次只会出现n个数字,有m次操作,那么最多的操作数就是n * m,再加上STL维护的logn复杂度,那么就是O(n * m * log(n * m)),很明显能过掉,求解成功。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
const int mod = 998244353 ;
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 ;
}

ll t , n , d , k , m , b[maxn] , a[maxn] ;
char s[maxn] ;
vector < int > q ;
void solve(){
	q.clear() ;
	n = read() ;
	m = read() ;
	k = read() ;
	q.push_back(k) ;
	for(int i = 1 ; i <= m ; i ++){
		ll u ;
		u = read() ;
		char c ;
		cin >> c ;
		if(c == '?'){
			set < int > p ;
			for(int j = 0 ; j < (int)q.size() ; j ++){
				p.insert(((q[j] + u) % n) == 0 ? n : (q[j] + u) % n) ;
				p.insert(((q[j] + n - u) % n) == 0 ? n : (q[j] + n - u) % n) ;
			}
			q.clear() ;
			for(auto it : p){
				q.push_back(it) ;
			}
		}
		if(c == '1'){
			set < int > p ;
			for(int j = 0 ; j < (int)q.size() ; j ++){
				p.insert(((q[j] + n - u) % n) == 0 ? n : (q[j] + n - u) % n) ;
			}
			q.clear() ;
			for(auto it : p){
				q.push_back(it) ;
			}
		}
		if(c == '0'){
			set < int > p ;
			for(int j = 0 ; j < (int)q.size() ; j ++){
				p.insert(((q[j] + u) % n) == 0 ? n : (q[j] + u) % n) ;
			}
			q.clear() ;
			for(auto it : p){
				q.push_back(it) ;
			}
		}
	}
	sort(q.begin() , q.end()) ;
	cout << q.size() << endl ;
	for(int i = 0 ; i < (int)q.size() ; i ++){
		cout << q[i] << " " ; 
	}
	cout << endl ;
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

E. Rudolf and k Bridges

虽然E的题意比较好描述,但是代码细节比较多,明天早上起来再补上。

谢谢大家的支持,如果喜欢作者的话记得点赞收藏加关注哦~

有任何问题也欢迎大家评论区评论或者私信我,本人码风不是特别好,请谅解。

  • 14
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小小许愿瓶

我的成长我做主

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

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

打赏作者

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

抵扣说明:

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

余额充值