当前位置:网站首页>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;
}
边栏推荐
- Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
- MySQL advanced (Advanced) SQL statement
- 中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
- MySQL
- ORA-01455: converting column overflows integer datatype
- Thread application instance
- ORA-01455: converting column overflows integer datatype
- IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
- Compile oglpg-9th-edition source code with clion
- 以太网PHY层芯片LAN8720A简介
猜你喜欢
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
教程篇(5.0) 09. RESTful API * FortiEDR * Fortinet 网络安全专家 NSE 5
数据降维——主成分分析
《重构:改善既有代码的设计》读书笔记(上)
开发固定资产管理系统,开发固定资产管理系统用什么语音
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
Chic Lang: completely solve the problem of markdown pictures - no need to upload pictures - no need to network - there is no lack of pictures forwarded to others
Develop fixed asset management system, what voice is used to develop fixed asset management system
Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出
冒泡排序数组
随机推荐
新手必看,點擊兩個按鈕切換至不同的內容
Digital scroll strip animation
xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
Gstore weekly gstore source code analysis (4): black and white list configuration analysis of security mechanism
451-memcpy、memmove、memset的实现
End to end object detection with transformers (Detr) paper reading and understanding
MySQL
QT中的QPropertyAnimation使用和toast案列
Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
2022.7.1-----leetcode.241
C file input operation
仿京东放大镜效果(pink老师版)
Learn the knowledge points of eight part essay ~ ~ 1
golang:[]byte转string
多态的理解以及作用
线程应用实例
MySQL
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
PHP-Parser羽毛球预约小程序开发require线上系统
Thread application instance