01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)
题意: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)的更多相关文章
- 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 ...
- D1. Kirk and a Binary String (easy version)
D1. Kirk and a Binary String (easy version) 01串找最长不降子序列 给定字符串s,要求生成一个等长字符串t,使得任意l到r位置的最长不降子序列长度一致 从后 ...
- Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main ...
- Codeforces 1204D2. Kirk and a Binary String (hard version) (dp思路)
题目链接:http://codeforces.com/contest/1204/problem/D2 题目是给定一个01字符串,让你尽可能多地改变1变为0,但是要保证新的字符串,对任意的L,R使得Sl ...
- 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 ...
- 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 ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- 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 ...
- 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 ...
随机推荐
- MapBox
MapBox的地图API大家用过吗 用作网站或者APP的底图,就不用自己架设地图服务器了 发布自己的地图了 这跟Google Map是一样的道理,类似的还有天地图,高德,百度地图API等等. 属于前端 ...
- kali随便写 kali更新源配置
./ +文件目录 是执行文件的意思 kali修改更新源及更新 进入源文件进行修改 leafpad /etc/apt/sources.list (其实系统本身就自带了更新源,去掉其注释也是可以的,现在 ...
- tp5中很牛皮的一句sql语句,三个条件(两个不确定条件,一个硬性条件)
$result = Db::table('xxxxxx') // 表名 ->alias('g') ->join('xxxxx_2 u','g.user_id = u.id') -> ...
- git下载fastadmin
mac git下载后,环境配置运行会如下图 一 下载相对应系统的node.js https://nodejs.org/en/download/ 安装就是一直下一步.... 二 指令终端.cd 到对应项 ...
- itertools模块中的product方法
itertools模块中的product方法 itertools.product(*iterables[, repeat]) 笛卡尔积 创建一个迭代器,生成表示item1,item2等中的项目的笛卡尔 ...
- 最简SpringBoot程序制法
JDK:1.8.0_212 IDE:STS4(Spring Tool Suit4 Version: 4.3.2.RELEASE) 工程下载:https://files.cnblogs.com/file ...
- ZT:我们身边大多数的事都是暂时性的
1. 家庭放在首位. 2. 戒酒能有助于身体健康. 3. 经常跑步以及运动有益于身心健康. 4. 保证心胸开阔.让爱自动来到你的身边,而不需要你自己去拼命寻找. 5. 区分优秀的导师和老师.不断提升自 ...
- C#产生随机验证码的代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- linux读xml文件问题
由于从配置文件中读取到的路径名的最后多了个0x0A,害我折腾了半天. 提示也很奇葩: I/O warning : failed to load external entity 关键是从这个提示看不出是 ...
- GDAL OGR Tools
OGR2OGR ogr2ogr 使用文档 1. GeoJSON 转换 ShapeFile ogr2ogr -nlt POLYGON -skipfailures ground.shp ground.js ...