当前位置:网站首页>Educational Codeforces Round 129 (Rated for Div. 2) 补题题解
Educational Codeforces Round 129 (Rated for Div. 2) 补题题解
2022-07-02 18:27:00 【乔大先生】
Educational Codeforces Round 130 Rated for Div. 2
有段时间没练了,十几分钟过两道题,但是第三题还是思维能力不足没有过,继续练,加油
A Parkway Walk
简单思维,算一下距离和,然后让凳子间的距离减去就行
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
#define int long long
int T;
int a[N];
int n, m;
signed main()
{
cin>>T;
while(T -- ){
int res = 0;
cin>>n>>m;
for(int i = 0; i < n; i ++ ){
int t;
cin>>t;
res += t;
}
if(m >= res) cout<<0<<endl;
else{
cout<<res - m<<endl;
}
}
return 0;
}
B Promo
简单思维,排一下序,求一个前缀和,按要求将后面一部分前缀和输出即可
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
#define int long long
int T;
int a[N];
int n, m, q;
int res[N]; //前缀和数组
signed main()
{
cin>>n>>q;
for(int i = 1; i <= n; i ++ ){
cin>>a[i];
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i ++ ) res[i] = res[i - 1] + a[i];
// cout<<res[n]<<endl;
while(q -- ){
int x, y;
cin>>x>>y;
// cout<<n - x + y<<' '<<n - x<<"***"<<endl;
int op = res[n - x + y] - res[n - x];
cout<<op<<endl;
}
return 0;
}
C awoo’s Favorite Problem
思维题,比赛的时候没过,官方题解挺清楚的:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
string s, t;
int T;
int n;
int res1, res2;
bool st;
int main()
{
cin>>T;
while(T -- ){
res1 = 0;
res2 = 0;
s.clear();
t.clear();
cin>>n;
cin>>s;
cin>>t;
int j = 0;
st = false;
//b的数量不会变,如果两个字符串b的数量不同,则一定不能成一个字符串
for(int i = 0; i < n; i ++ ){
if(s[i] == 'b') res1 ++ ;
if(t[i] == 'b') res2 ++ ;
}
if(res1 != res2){
cout<<"NO"<<endl;
continue;
}
//变换s,让s与t相等
//a只能右移
//c只能左移
for(int i = 0; i < n; i ++ ){
if(s[i] == 'b'){
while(t[j] == 'b'){
//找到t中的第一个不为b的字母
j ++ ;
}
continue;
}
while(t[j] == 'b'){
//找到t中的第一个不为b的字母
j ++ ;
}
//s[i]可能为b,但是t[j]一定不为b,三种情况下两字符串永远无法相等
//①s[i]和t[j]去除b后遍历到的第一个不为b的字符不同,因为a、c无法跨过b互换,所以s一定无法通过移动变成t
//s[i]为a,但是此时s的指针在t的右边,因为a只能右移,所以s一定无法通过移动变成t
//s[i]为c,但是此时s的指针在t的左边,因为c只能左移,所以s一定无法通过移动变成t
if(s[i] != t[j] || (s[i] == 'a' && i > j) || (s[i] == 'c' && i < j)){
st = true;
break;
}
j ++ ;
if(i == n - 1 && t[j] == 'b') res2 ++ ;
}
if(st){
cout<<"NO"<<endl;
continue;
}
else cout<<"YES"<<endl;
}
return 0;
}
边栏推荐
- #gStore-weekly | gStore源码解析(四):安全机制之黑白名单配置解析
- 2022.7.1-----leetcode. two hundred and forty-one
- Yolov3 trains its own data set to generate train txt
- SIFT feature point extraction "suggestions collection"
- Getting started with typescript
- Use cheat engine to modify money, life and stars in Kingdom rush
- Binary operation
- 使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
- Date tool class (updated from time to time)
- Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
猜你喜欢
Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
Markdown basic grammar
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
Excel finds the same value in a column, deletes the row or replaces it with a blank value
搭建哨兵模式reids、redis从节点脱离哨兵集群
Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
Data dimensionality reduction principal component analysis
《重构:改善既有代码的设计》读书笔记(上)
Introduction to the paper | application of machine learning in database cardinality estimation
随机推荐
仿京东放大镜效果(pink老师版)
Npoi export Excel2007
Quanzhi A33 uses mainline u-boot
守望先锋世界观架构 ——(一款好的游戏是怎么来的)
C file input operation
Page title component
Develop fixed asset management system, what voice is used to develop fixed asset management system
Markdown basic grammar
Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
ORA-01455: converting column overflows integer datatype
思考变量引起的巨大变化
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
[paper reading] Ca net: leveraging contextual features for lung cancer prediction
A4988 drive stepper motor "recommended collection"
metric_logger小解
juypter notebook 修改默认打开文件夹以及默认浏览器
How to print mybats log plug-in using XML file
Novice must see, click two buttons to switch to different content
Introduction of Ethernet PHY layer chip lan8720a