CF1204D2 Kirk and a Binary String

思路

易发现在一个区间中,比较靠前的一可以换成0


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define maxn 100100
using namespace std ;
int tmpp ;
char s[maxn] , t[maxn] ;
int main () {
	cin >> s;
	int len = strlen(s) ;
	for(int i = 1 ; i <= len ; i ++) {
		t[i] = s[i] ;
	}
	for(int i = len - 1 ; i >= 0 ; i --) {
		if(s[i] == '1' && tmpp >= 0) {
			t[i] = '0' ;
		}
		int cur = s[i] == '1' ? 1 : -1 ;
		tmpp = min(tmpp+cur,cur) ;
	}
	cout << t << endl ;
	return 0 ;
}
posted @ 2019-08-21 16:47  _L_Y_T  阅读(176)  评论(0编辑  收藏  举报