Codeforces Round 933 (Div. 3) A~D

比赛链接 :

codeforces.com/contest/1941

A . Rudolf and the Ticket

直接暴力即可 ;

复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;
const int mod = 1e9+7;
const int N = 2000;

using namespace std;

int a[N] ,b[N] ;

inline void solve(){
	int n , m , k ; cin >> n >>  m >>  k ;
	for(int i=1;i<=n;i++) cin >> a[i] ;
	for(int i=1;i<=m;i++) cin >> b[i] ;
	int 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 ;
}
 
signed main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

B. Rudolf and 121

用贪心的思路 , 这个肯定是要从前往后来遍历的 ;

从左到右遍历一遍,最后看数组是不是全为0即可 ;

复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

using namespace std;
int a[N] ;

inline void solve() {
	int n ; cin >> n ;
	for(int i=1;i<=n;i++) {
		cin >> a[i] ;
	}
	bool tag = true  ;
	for(int i=2;i<=n-1;i++){
		int x = a[i-1] ;
		a[i-1] -= x ;
		a[i] -= 2 * x ;
		a[i+1] -= x ;
		if(a[i]<0 || a[i+1]<0){
			tag = false ;
			break ;
		} 
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=0){
			tag = false ;
			break ;
		}
	}
	if(tag) cout << "YES" << endl ;
	else cout << "NO" << endl ;
}

signed main()
{
    IOS
    int _ = 1;
    cin >> _;
    while (_--) solve();
    return 0;
}

C. Rudolf and the Ugly String

因为"map" 和 pie其实是互不相关的, 那么我们可以找到一个map就删掉a,找到一个pie的话,就删掉一个i,这样从前往后遍历即可 ,就是最优答案 ;

复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
typedef long long LL;
const int mod = 1e9+7;
const int N = 2e5+10;

using namespace std;

string a = "pie" , b = "map" ;

inline void solve(){
	int n ; cin >> n ;
	string s ; cin >> s ;
	s = ' ' + s ;
	vector<int> idx ;
	bool tag = true ;
	for(int i=1;i<=n-2;i++){
		if(s.substr(i,3) == a || s.substr(i,3) == b){
			idx.push_back(i) ;
			i += 2 ;
		}
	} 
	if(idx.size() == 0){
		cout << 0 << endl ;
		return ;
	}else{
		cout << (int)(idx.size()) << endl ;
	}
	
}
 
signed main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

D. Rudolf and the Ball Game

其实这题最重要的条件是 n * m <= 2e5:

那我们可以放心大胆的写二重循环来解决 ;

用一个bool数组dp记录当前的状态,dpi为true表示(i+1)人手里有球,为false表示无球,下一次的变化,用 一个bool数组g表示,遍历(0,n)对每一个dpi = true 的进行处理,也就是ci==0,1,?的三种情况分别处理即可 ;

复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
typedef long long LL;
const int mod = 1e9+7;
const int N = 1e3+10;
using namespace std;

inline void solve(){
	int n , m , x ; cin >> n >> m >> x ;
	vector<int> dp(n) ;
	x --; // 处理下标 
	dp[x] =  1;
	for(int i=0;i<m;i++){
		int r ; char c ; 
		cin >> r >> c ;
		vector<int> g(n) ;// 代替dp数组的数组
		for(int k=0;k<n;k++){
			if(dp[k]){
				if(c!='1') g[(k+r)%n] = 1 ;
				if(c!='0') g[(k-r+n)%n] = 1 ;
			}
		} 
		dp = g ;
	}
	int ans = count(dp.begin(),dp.end(),1) ;
	cout << ans << endl ;
	for(int i=0;i<n;i++){
		if(dp[i]){
			cout << i + 1 << " " ;
		}
	}
	cout << endl ;	
}
 
signed main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}
相关推荐
吞下星星的少年·-·8 小时前
Div.2 CF 1130B题(构造,贪心)
算法·贪心·构造
ShineWinsu9 小时前
对于Qt:QRadioButton常见属性以及QButtonGroup的解析
数据库·c++·qt·microsoft·gui·qradiobutton·qbuttongroup
傲世仙尊9 小时前
多态-虚表才活到运行期符号表早已消失
c++
chenbingjie_c9 小时前
C++ 多态完全指南:从虚函数重写到虚函数表原理
开发语言·c++
是main不是漫9 小时前
【双指针——移动零】数组划分类题目的入门基石
c++·算法
·present·9 小时前
CSAPP(Bomb lab)
c语言·c++
王老师青少年编程10 小时前
2026年信奥赛c++普及组csp-j第二轮复赛真题
c++·真题·csp·信奥赛
深圳市快瞳科技有限公司10 小时前
野外鸟类AI识别落地实录:输入适配、结构化输出、去重聚合与置信度分流的工程实践
算法·计算机视觉·鸟类识别·鸟类ai识别·野外鸟类观测·林业调查
时间的拾荒人11 小时前
CMake 常用命令详解:从版本声明到安装部署
c++·面试
专注仿真12 小时前
梯度提升类(XFBoost)算法详解与代码实例
开发语言·人工智能·python·算法·大模型训练·控制算法