CF1774C Ice and Fire(贪心)

该文描述了一个编程挑战,题目来自Codeforces和洛谷平台。问题涉及在0和1序列中确定能存活到最后的数字数量。给定一个字符串s,程序需计算在连续的0或1串中,最多可以有多少个数在特定规则下生存下来。解决方案包括遍历字符串,计数连续的0和1,并输出每个位置的最大存活数。
摘要由CSDN通过智能技术生成

Problem - C - Codeforces

Ice and Fire - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

求1~i中有多少个数有可能活到最后
在一段连续的0或者连续的1中只能有1个存活下来
连续段前面通过合理的安排 每个数 都有可能活到最后,
#include <bits/stdc++.h>
#include <iostream>
#include<unordered_map>
#include<unordered_set>
#define x first
#define y second
#define  ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

using namespace std;

typedef  long  long LL ;
typedef  unsigned long  long ULL ;
typedef pair<int,int> PII ;
typedef pair<LL,int> PLI ;
const int N = 1e9;

int n,m,q;


inline void solve()
{
    int n;string s;
    cin >> n >> s;
    int cnt0=0,cnt1=0;
    for(int i=0;i < n-1 ;i ++ )
    {
        if(s[i] == '0'){
            cnt1= 0;cnt0 ++ ;
        }
        else
        {
            cnt1 ++ ;cnt0=0;
        }
        cout << i + 1 - max(cnt0,cnt1) + 1 << " ";
    }
    cout  << endl;
}
signed main()
{
    ios

    int T=1;
    cin>>T;
    while(T -- )
    {
        solve();

    }


    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值