当前位置:网站首页>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;
}
边栏推荐
- Processing strategy of message queue message loss and repeated message sending
- 冒泡排序数组
- Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
- Emmet basic syntax
- Microservice technology - distributed global ID in high concurrency
- 《重构:改善既有代码的设计》读书笔记(下)
- Learn the knowledge points of eight part essay ~ ~ 1
- 机器学习笔记 - 时间序列预测研究:法国香槟的月销量
- 高级性能测试系列《24. 通过jdbc执行sql脚本》
- Yolov3 trains its own data set to generate train txt
猜你喜欢

教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5

Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5

Talk about the design of red envelope activities in e-commerce system

Compile oglpg-9th-edition source code with clion

搭建哨兵模式reids、redis从节点脱离哨兵集群

Use cheat engine to modify money, life and stars in Kingdom rush

Why should we build an enterprise fixed asset management system and how can enterprises strengthen fixed asset management

高级性能测试系列《24. 通过jdbc执行sql脚本》

《重构:改善既有代码的设计》读书笔记(下)

Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
随机推荐
What is the MySQL backup suffix_ MySQL backup restore
Qpropertyanimation use and toast case list in QT
搭建哨兵模式reids、redis从节点脱离哨兵集群
juypter notebook 修改默认打开文件夹以及默认浏览器
451-memcpy、memmove、memset的实现
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
2022 software engineering final exam recall Edition
[0701] [paper reading] allowing data imbalance issue with perforated input during influence
教程篇(5.0) 09. RESTful API * FortiEDR * Fortinet 网络安全专家 NSE 5
Develop fixed asset management system, what voice is used to develop fixed asset management system
Imitation Jingdong magnifying glass effect (pink teacher version)
使用xml文件打印mybaties-log插件的方式
ICDE 2023|TKDE Poster Session(CFP)
What is 9D movie like? (+ common sense of dimension space)
Use cheat engine to modify money, life and stars in Kingdom rush
C的内存管理
注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
Advanced performance test series "24. Execute SQL script through JDBC"
仿京东放大镜效果(pink老师版)
PHP asymmetric encryption method private key and public key encryption and decryption method