Codeforces Round #788 (Div. 2)
A - Prof. Slim
遇到的问题:
一开始读错题,到后面思路打不开,最后想了好久才知道怎么做。总感觉思维差很多,其实这种题还是很好想到的,我为什么想的那么慢?我认为应该是要好好反思一下自己,要注意哪方面的问题了。
代码:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
typedef pair<int,int>PII;
const int N = 2e5 + 10;
int a[N];
void solve() {
int n;
cin >> n;
int cnt = 0;
for(int i = 0; i < n; i++) {
cin >> a[i];
if(a[i] < 0) cnt++;
}
// cout << cnt << endl;
for(int i = 0; i < n; i++) {
if(a[i] > 0 && cnt) {
a[i] = -a[i];
cnt--;
}else if(a[i] < 0 && cnt) cnt--;
else if(cnt == 0 && a[i] < 0) a[i] = -a[i];
}
// for(int i = 0; i < n; i++) cout << a[i] << ' ';
// cout << endl;
bool flag = true;
for(int i = 0; i < n; i++) {
if(a[i] < a[i-1] && i) {
flag = false;
break;
}
}
if(flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
signed main() {
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}
B - Dorms War
遇到的问题:
怎么说呢,一开始想到怎么做了,但是做的都太复杂了,每次都是最后化简才做出来。以后写题的时候,先想清楚吧,要不然挺浪费时间的。
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
typedef pair<int,int>PII;
const int N = 30;
bool st[N];
void solve() {
string s;
int k, n;
cin >> n;
cin >> s;
cin >> k;
memset(st, false, sizeof st);
for(int i = 0; i < k; i++) {
char c;
cin >> c;
st[c-'a'] = true;
}
int ans = 0;
int pos = 0;
for(int i = 0; i < n; i++) {
if(st[s[i] - 'a']) {
ans = max(ans, i - pos);
pos = i;
}
}
cout << ans << endl;
}
signed main() {
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)