总结
guagua1904 · · 个人记录
1、T678004 蹦床(jump)
这道题要用到一个预处理的思想,首先呢我们把最基础的只给最基础的次数求出来求出来就是这个
然后呢就是重点了,判断如果从这个点开始跳的次数已经≥
最后我们输出ans就行了,但是要注意要开long long不然只有30分。
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
int num[5005];
int a[5005];
signed main(){
int T;
cin>>T;
while(T--){
memset(a,0,sizeof a);
memset(num,0,sizeof num);
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
int ans=0;
for(int i=1;i<=n;i++){
for(int j=i+2;j<=min(i+a[i],n);j++)num[j]++;
if(num[i]>=a[i])num[i+1]+=num[i]-(a[i]-1);
else if(num[i]<a[i])ans+=a[i]-1-num[i];
}
cout<<ans<<'\n';
}
return 0;
}
2、T678244 太空旅行(space)
这道题就是把向上下左右的偏移都记录一下,然后判断一下距离即可,非常的简单,差一点写出来了但是没时间了。
就是看你超过的能不能靠删除足量的相反方向来搞定🤝
代码:
#include<bits/stdc++.h>
using namespace std;
int t, x, y, xx, yy;
string s;
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> t;
while (t--) {
long long a = 0, b = 0, c = 0, d = 0;
bool f1 = 0, f2 = 0;
xx = 0, yy = 0;
cin >> x >> y;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'U') a++;
else if (s[i] == 'D') b++;
else if (s[i] == 'R') c++;
else d++;
}
if (x >= 0) {
if (c >= x) f1 = 1;
} else if (x <= 0) {
if (d >= abs(x)) f1 = 1;
}
if (y >= 0) {
if (a >= y) f2 = 1;
} else if (y <= 0) {
if (b >= abs(y)) f2 = 1;
}
if (f1 == 1 and f2 == 1) {
cout << "YES" << '\n';
} else {
cout << "NO" << '\n';
}
}
return 0;
}
3、T678245 回文串(string)
这道题直接模拟加双指针可以卡过去但是改了时间就过不了了。
这道题思路是用一个cnt来记录字符串不相等的数量,然后
然后修改操作:
利用
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
int n = s.size();
int q;
cin >> q;
int cnt = 0;
for(int i = 0; i < n / 2; i++){
if(s[i] != s[n - i - 1]) cnt++;
}
while(q--){
int x;
cin >> x;
char c;
cin >> c;
x--;
int y = n - x - 1;
if(s[x] != s[y]) cnt--;
s[x] = c;
if(s[x] != s[y]) cnt++;
if(cnt){
cout << "No\n";
} else {
cout << "Yes\n";
}
}
return 0;
}