题意:https://codeforc.es/problemset/problem/1204/D2

给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 l~r 的LIS最长上升子序列长度不变)。

问:0111001100111011101000

答:0011001100001011101000

思路:

参考题解:考虑什么串无法该变。

1. 10无法被改变(我们称为固定串),00,01,11都可以改。

2. 固定串+固定串(无法被改变)。

3. 1+固定串+0(无法被改变)。

所以固定串也就是类似于:111000101100 之类的。

容易想到:固定串是可以直接删除的,比如:01+110010+1 == 00+110010+0 ,不会影响前后(而且我们发现0和1的数量相等),而且你也不可能去改固定串。

所以我们可以不断的剔除固定串。

那剩下的1就全是可以改为0的了。

问题也就转变成了一个类似括号匹配的问题,我们就从后往前记录0的个数,把能匹配10的1标记好,最后把没有标记的1变成0就行了。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; char s[N];
bool f[N]; int main()
{
int l;
s[]='$';
sc("%s",s+);
l=strlen(s)-;
int cnt=;
for(int i=l;i>=;--i)
{
if(s[i]=='')
cnt++;
else
{
if(cnt)
cnt--,f[i]=;
}
}
fo(i,,l)
if(s[i]==''&&!f[i])
s[i]='';
pr("%s\n",s+);
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)的更多相关文章

  1. D2. Kirk and a Binary String (hard version) D1 Kirk and a Binary String (easy version) Codeforces Round #581 (Div. 2) (实现,构造)

    D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 meg ...

  2. D1. Kirk and a Binary String (easy version)

    D1. Kirk and a Binary String (easy version) 01串找最长不降子序列 给定字符串s,要求生成一个等长字符串t,使得任意l到r位置的最长不降子序列长度一致 从后 ...

  3. Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main ...

  4. Codeforces 1204D2. Kirk and a Binary String (hard version) (dp思路)

    题目链接:http://codeforces.com/contest/1204/problem/D2 题目是给定一个01字符串,让你尽可能多地改变1变为0,但是要保证新的字符串,对任意的L,R使得Sl ...

  5. Codeforces Round #581 (Div. 2)A BowWow and the Timetable (思维)

    A. BowWow and the Timetable time limit per test1 second memory limit per test256 megabytes inputstan ...

  6. Codeforces Round #539 (Div. 2) - D. Sasha and One More Name(思维)

    Problem   Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem ...

  7. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  8. 01背包 Codeforces Round #267 (Div. 2) C. George and Job

    题目传送门 /* 题意:选择k个m长的区间,使得总和最大 01背包:dp[i][j] 表示在i的位置选或不选[i-m+1, i]这个区间,当它是第j个区间. 01背包思想,状态转移方程:dp[i][j ...

  9. Codeforces Round #599 (Div. 2) D. 0-1 MST(bfs+set)

    Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers ...

随机推荐

  1. numpy中np.max() 和 np.maximum() 的区别

    np.max(a, axis=None, out=None, keepdims=False) # 接收一个参数a # 取a 在 axis方向上的最大值 np.maximum(x, y) # 接收两个参 ...

  2. Android蓝牙通信

    Android为蓝牙设备之间的通信封装好了一些调用接口,使得实现Android的蓝牙通信功能并不困难.可通过UUID使两个设备直接建立连接. 具体步骤: 1. 获取BluetoothAdapter实例 ...

  3. PTA 重构二叉树

    重构二叉树 (25 分) 给出两个字符串,分别表示二叉树的先序遍历(根.左子树.右子树)和中序遍历(左子树.根.右子树)的结果. 例如,对于下面的二叉树,先序遍历结果是DBACEGF,中序遍历结果是A ...

  4. $message的问题

    项目中出现$message的问题: 拉取数据成功后 this.$message.success("数据拉取成功")点击拉取第一次不出现,但是代码执行了,后来多次点击就出现了 原因: ...

  5. LNMP源码编译

    LNMP源码编译 编译安装之前把开发包组安装了 [root@tiandong63 ~]# yum groupinstall "Development Tools" "De ...

  6. From 7.15 To 7.21

    From 7.15 To 7.21 大纲 竞赛 一周七天, 总共做三十五到四十道题吧, 题解要一起写了, 周六之前写不完的话就只能回家补咯 加上考试题总共做了25道题... 还要学计算几何, 生成函数 ...

  7. UEFI和GPT

    好就没用linux了,这几天在win8笔记本上用虚拟机装了下,也准备装到硬盘上和win8双系统使用,发现一些概念已经跟不上时代了. 一个是在虚拟机中装的时候,分配了虚拟硬盘分区时,提示选择分区表类型, ...

  8. android data binding jetpack V 实现recyclerview 绑定

    android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...

  9. TcpSendRcv方法笔记1

    if (ns.DataAvailable) return ns.ReadByte(); ns.DataAvailable:获取一个值,该值指示在要读取的 NetworkStream 上是否有可用的数据 ...

  10. PHP中获取当前页面的完整URL、PHP URL处理、获取不带扩展名的文件名

    javascript实现: top.location.href 顶级窗口的地址this.location.href 当前窗口的地址 PHP实现 #测试网址: http://localhost/blog ...