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 ...
随机推荐
- codeforces1C
Ancient Berland Circus CodeForces - 1C 如今,Berland 的所有马戏表演都有一个圆形的竞技场,其直径为 13 米,但过去的情况有所不同. 在古代 Berlan ...
- ngx_http_auth_request_module 第三方认证
shell > vim /usr/local/nginx-1.10.2/conf/vhost/auth.conf # 这是第三方认证服务器,认证逻辑使用的 PHP 代码 server { lis ...
- JavaWeb_(Struts2框架)Action中struts-default下result的各种转发类型
此系列博文基于同一个项目已上传至github 传送门 JavaWeb_(Struts2框架)Struts创建Action的三种方式 传送门 JavaWeb_(Struts2框架)struts.xml核 ...
- Vue_(组件通讯)动态组件
动态组件 传送门 在一个元素上挂载多个组件,根据不同状态进行切换的时候,可以使用动态组件 动态组件的使用:需要使用内置组件<component></component>,根据 ...
- Idea关于Lombok的一些问题( java: 找不到符号 符号)
22:15 Lombok Requires Annotation Processing Annotation processing seems to be disabled for the proje ...
- pandas.Series.value_counts
pandas.Series.value_counts Series.value_counts(normalize=False, sort=True, ascending=False, bins=Non ...
- python全栈开发第7天 nginx服务器和nfs的搭建及组成集群的方法
作业一:nginx服务 二进制安装nginx包 1.使用命令:yum install epel-release -y ,来安装epel,安装成功如下图:(因为我用32位的centos7老是出现各种各样 ...
- slab分配object
在numa架构下,slab分配object: 3192static __always_inline void * 3193__do_cache_alloc(struct kmem_cache *cac ...
- 从GoogleClusterData统计每个用户的使用率、平均每次出价
之前将google cluster data导入了Azure上的MySQL数据库,下一步就是对这些数据进行分析, 挖掘用户的使用规律了. 首先,为了加快执行速度,对user,time等加入索引. 然后 ...
- 虚拟化技术原理(CPU、内存、IO)
本文来自:http://www.ywnds.com/?p=5856 虚拟化 云计算现在已经非常成熟了,而虚拟化是构建云计算基础架构不可或缺的关键技术之一. 云计算的云端系统, 其实质上就是一个大型的分 ...