当前位置: 首页 > news >正文

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()
{IOSint _ = 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()
{IOSint _ = 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()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}

 D. Rudolf and the Ball Game

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

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

用一个bool数组dp记录当前的状态,dp[i]为true表示(i+1)人手里有球,为false表示无球,下一次的变化,用 一个bool数组g表示,遍历(0,n)对每一个dp[i] = true 的进行处理,也就是c[i]==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()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}

http://www.lryc.cn/news/316639.html

相关文章:

  • 《vtk9 book》 官方web版 第3章 - 计算机图形基础 (3 / 5)
  • pytorch 函数整理
  • docker实战之制作filebeat镜像
  • 【DAY11 软考中级备考笔记】数据结构 查找和排序
  • 华为机考:HJ102 字符统计
  • 安装配置HBase
  • 【更新】数字金融与企业ESG表现:效应、机制与“漂绿”检验数据集(2011-2022年)
  • 手写简易操作系统(五)--获得物理内存容量
  • 机器学习之DeepSequence软件使用学习3-预测突变效应
  • Linux文件与文件系统的压缩
  • ubuntu 中进入python 编辑如何退出到命令行
  • 2024.3.12 C++
  • 飞塔防火墙开局百篇——002.FortiGate上网配置——透明模式配置(Transparent)
  • 代码随想录算法训练营第52天|300.最长递增子序列 674.最长连续递增序列 718.最长重复子数组
  • 分享一些开源的游戏仓库
  • Java详解:单列 | 双列集合 | Collections类
  • Centos7 使用docker来部署mondb
  • Java SE入门及基础(35)
  • 基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的常见车型识别系统(Python+PySide6界面+训练代码)
  • Sqoop 学习
  • Ollama 只安装 Ollama,本地快速部署谷歌开源大模型Gemma(基于Ollama)
  • 一条 sql 语句可能导致的表锁和行锁以及死锁检测
  • prometheus 原理(架构,promql表达式,描点原理)
  • Linux的目录结构(介绍主要的)
  • 推房子游戏c++
  • docker学习入门篇
  • 【Spring Boot 3】动态注入和移除Bean
  • 555经典电路
  • vue 下载的插件从哪里上传?npm发布插件详细记录
  • 吴恩达机器学习笔记 十七 通过偏差与方差诊断性能 正则化 偏差 方差