Acwing第 68 场周赛【未完结】
AcWing 周赛 68
2023-09-11 14:15:52 时间
https://www.acwing.com/activity/content/competition/problem_list/2274/
4612. 去掉0【双指针】
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int t; cin>>t;
while(t--)
{
string s; cin>>s;
vector<int>ve;
int ans=0;
for(int i=0;i<s.size();i++)
{
if( (s[i]=='1') && (i+1<s.size()) && (s[i+1]=='0') )
{
int j=i+1;
while( (j+1)<s.size() && (s[j+1]=='0') ) j++;
if(j+1<s.size()&&s[j+1]=='1') ans+=j-i;
}
}
cout<<ans<<endl;
}
return 0;
}
4613. 方格跳跃【前缀和】
前缀和,左右分别扫一遍即可。
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*3+10;
int st[N];
int main(void)
{
int n; cin>>n;
string s; cin>>s;
s=")"+s;
for(int i=n;i>=1;i--)
{
if(s[i]=='<') st[i]=1;
st[i]=max(st[i],st[i+1]);
}
int cnt=0;
for(int i=1;i<=n;i++) if(s[i]=='>'&&!st[i+1]) cnt++;
memset(st,0,sizeof st);
for(int i=1;i<=n;i++)
{
if(s[i]=='>') st[i]=1;
st[i]=max(st[i],st[i-1]);
}
for(int i=1;i<=n;i++) if(s[i]=='<'&&!st[i-1]) cnt++;
cout<<cnt;
return 0;
}
相关文章
- Acwing第 70 场周赛【未完结】
- Acwing第 69 场周赛【完结】
- Acwing第 66 场周赛【完结】
- Acwing第 64 场周赛【未完结】
- Acwing第 47 场周赛【完结】
- Acwing第 34 场周赛【完结】
- Acwing第 21 场周赛【完结】
- Acwing第 11 场周赛【未完结】
- Acwing第 5 场周赛【未完结】
- Acwing第 3 场周赛【完结】
- AcWing 3250. 通信网络
- LeetCode周赛 + AcWing周赛(T4/T3)分析对比
- [AcWing]898. 数字三角形
- [Acwing]836. 合并集合
- [AcWing]830. 单调栈
- 196、【动态规划】AcWing —— 285. 没有上司的舞会(C++版本)
- 190、【动态规划】AcWing ——282. 石子合并(C++版本)
- 156、【动态规划】AcWing ——3. 完全背包问题:二维数组+一维滚动数组(C++版本)