当前位置:网站首页>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;
}
边栏推荐
- 使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
- MySQL advanced (Advanced) SQL statement
- Develop fixed asset management system, what voice is used to develop fixed asset management system
- 为什么要做企业固定资产管理系统,企业如何加强固定资产管理
- Typescript 之 快速入门
- Markdown基础语法
- 仿京东放大镜效果(pink老师版)
- MySQL表历史数据清理总结
- LeetCode 0871. Minimum refueling times - similar to poj2431 jungle adventure
- Talk about the design of red envelope activities in e-commerce system
猜你喜欢

zabbix5客户端安装和配置

守望先锋世界观架构 ——(一款好的游戏是怎么来的)

Thread application instance

搭建主从模式集群redis

Use cheat engine to modify money, life and stars in Kingdom rush
冒泡排序数组

注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机

【测试开发】软件测试—概念篇

End to end object detection with transformers (Detr) paper reading and understanding

Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
随机推荐
2022 software engineering final exam recall Edition
LeetCode 0871.最低加油次数 - 类似于POJ2431丛林探险
"Patient's family, please come here" reading notes
IEDA refactor的用法
Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5
Yunna | why use the fixed asset management system and how to enable it
使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
Emmet基础语法
横向越权与纵向越权[通俗易懂]
4274. Suffix expression - binary expression tree
新手必看,点击两个按钮切换至不同的内容
数据降维——因子分析
移动机器人路径规划:人工势场法[通俗易懂]
Juypter notebook modify the default open folder and default browser
Develop fixed asset management system, what voice is used to develop fixed asset management system
《重构:改善既有代码的设计》读书笔记(下)
SIFT特征点提取「建议收藏」
The mybatieshelperpro tool can be generated to the corresponding project folder if necessary