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;
}