当前位置:网站首页>Educational codeforces round 129 (rated for Div. 2) supplementary problem solution
Educational codeforces round 129 (rated for Div. 2) supplementary problem solution
2022-07-02 19:39:00 【Mr. Qiao Da】
Educational Codeforces Round 130 Rated for Div. 2
I haven't practiced for a while , Two questions in ten minutes , But the third question is still lack of thinking ability , Keep practicing , come on.
A Parkway Walk
Simple thinking , Calculate the distance and , Then subtract the distance between the stools
#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
Simple thinking , Arrange the order , Find a prefix and , Prefix and output the following part as required
#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]; // Prefixes and arrays
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
Thinking questions , It's not too late for the game , The official solution is quite clear :
#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 The number of will not change , If two strings b The number of different , Then it must not be a string
for(int i = 0; i < n; i ++ ){
if(s[i] == 'b') res1 ++ ;
if(t[i] == 'b') res2 ++ ;
}
if(res1 != res2){
cout<<"NO"<<endl;
continue;
}
// Transformation s, Give Way s And t equal
//a Can only move right
//c It can only be moved to the left
for(int i = 0; i < n; i ++ ){
if(s[i] == 'b'){
while(t[j] == 'b'){
// find t The first of them is not b The letter of
j ++ ;
}
continue;
}
while(t[j] == 'b'){
// find t The first of them is not b The letter of
j ++ ;
}
//s[i] May be b, however t[j] It must not be for b, In three cases, two strings can never be equal
//①s[i] and t[j] Remove b The first one traversed after is not b Different characters , because a、c Unable to cross b swap , therefore s It must not be able to become t
//s[i] by a, But at this time s The pointer is in t To the right of , because a Can only move right , therefore s It must not be able to become t
//s[i] by c, But at this time s The pointer is in t Left side , because c It can only be moved to the left , therefore s It must not be able to become 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;
}
边栏推荐
- AcWing 1131. 拯救大兵瑞恩 题解(最短路)
- Refactoring: improving the design of existing code (Part 1)
- Typescript 之 快速入门
- 4274. Suffix expression - binary expression tree
- SIFT feature point extraction "suggestions collection"
- 电脑使用哪个录制视频软件比较好
- 简书自动阅读
- 《代码整洁之道》读书笔记
- 机器学习笔记 - 时间序列预测研究:法国香槟的月销量
- How to print mybats log plug-in using XML file
猜你喜欢
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
Watchful pioneer world outlook Architecture - (how does a good game come from)
Zabbix5 client installation and configuration
Usage of ieda refactor
rxjs Observable 自定义 Operator 的开发技巧
ShardingSphere-JDBC5.1.2版本关于SELECT LAST_INSERT_ID()本人发现还是存在路由问题
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
Advanced performance test series "24. Execute SQL script through JDBC"
450-深信服面经1
Idea editor removes SQL statement background color SQL statement warning no data sources are configured to run this SQL And SQL dialect is not config
随机推荐
MySQL
安装单机redis详细教程
How to print mybats log plug-in using XML file
NMF-matlab
AcWing 1137. Select the best line solution (the shortest circuit)
ShardingSphere-JDBC5.1.2版本关于SELECT LAST_INSERT_ID()本人发现还是存在路由问题
AcWing 1126. 最小花费 题解(最短路—dijkstra)
《代碼整潔之道》讀書筆記
Educational Codeforces Round 129 (Rated for Div. 2) 补题题解
Golang concurrent programming goroutine, channel, sync
从20s优化到500ms,我用了这三招
A4988驱动步进电机「建议收藏」
AcWing 383. Sightseeing problem solution (shortest circuit)
VBScript详解(一)
Chapter 7 - class foundation
Codeworks round 802 (Div. 2) pure supplementary questions
LeetCode 0871.最低加油次数 - 类似于POJ2431丛林探险
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
Refactoring: improving the design of existing code (Part 1)
SIFT feature point extraction "suggestions collection"