cf round 598div3 D.Binary String Minimizing
题目:https://codeforces.com/contest/1256/problem/D
题意:给你长度为n的01串,能将任意两相邻字符交换k次,求最小字典序的交换结果。
思路:贪心...甚至不用二分...贴一发简短的代码
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,p=;
long long k;
char ch[maxn]={};
scanf("%d%lld",&n,&k);
scanf("%s",ch);
for(int i=;i<n;i++)
{
if(ch[i]=='')
{
if(k>i-p)swap(ch[i],ch[p]),k-=i-p;
else {swap(ch[i],ch[i-k]);break;}
p++;
}
}
printf("%s\n",ch);
}
return ;
}
cf round 598div3 D.Binary String Minimizing的更多相关文章
- Codeforces Round #598 (Div. 3) D. Binary String Minimizing 贪心
D. Binary String Minimizing You are given a binary string of length n (i. e. a string consisting of ...
- Codeforces Round #598 (Div. 3) D. Binary String Minimizing
You are given a binary string of length nn (i. e. a string consisting of nn characters '0' and '1'). ...
- CF 1107 E. Vasya and Binary String
E. Vasya and Binary String 链接 分析: 对于长度为x的一段序列,我们可以dp出消除的过程的最优方案,背包即可. 然后区间dp,可以先合并完所有的点,即没相同的一段区间合并为 ...
- CF 1003B Binary String Constructing 【构造/找规律/分类讨论】
You are given three integers a, b and x. Your task is to construct a binary string s of length n=a+b ...
- 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 ...
- Educational Codeforces Round 94 (Rated for Div. 2) String Similarity、RPG Protagonist、Binary String Reconstruction、Zigzags 思维
题目链接:String Similarity 题意: 首先题目定义了两个串的相似(串的构成是0.1),如果两个串存在对于一个下标k,它们的值一样,那么这两个串就相似 然后题目给你一个长度为2n-1的串 ...
- Binary String Matching
问题 B: Binary String Matching 时间限制: 3 Sec 内存限制: 128 MB提交: 4 解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...
- NYOJ之Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose a ...
- ACM Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
随机推荐
- php+mysql 实现无限极分类
php+mysql 实现无限极分类<pre>id name pid path 1 电脑 0 0 2 手机 0 0 3 笔记本 1 0-1 4 超级本 3 0-1-3 5 游戏本 3 0-1 ...
- variable precision SWAR算法
计算二进制形式中1的数量这种问题,在各种刷题网站上比较常见,以往都是选择最笨的遍历方法“蒙混”过关.在了解Redis的过程中接触到了variable precision SWAR算法(以下简称VP-S ...
- Linux系统中nc工具那些不为人知的用法
Linux nc命令用法 参考地址:https://www.cnblogs.com/jjzd/p/6306273.html -g<网关>:设置路由器跃程通信网关,最多设置8个; -G< ...
- 网站搭建-windows 系统 本地 网站搭建 - IIS
上一章有提到IIS安装,现在打开它: 点击浏览,如果没有启动的话,先点击启动. ip先选好,第一个吧,本机的(IIS自己提供了初始网页的东西). 然后可以自己去https://www.freemoba ...
- 前端与算法 leetcode 7. 整数反转
目录 # 前端与算法 leetcode 7. 整数反转 题目描述 概要 提示 解析 解法 算法 传入测试用例的运行结果 执行结果 GitHub仓库 # 前端与算法 leetcode 7. 整数反转 题 ...
- ffmpeg centos yum安装
CentOS 6&7安装ffmpeg CentOS 6和7安装方法是不一样的,下面分别说明: 安装前都需要先安装epel扩展源 yum -y install epel-release ce ...
- 通过 position:fixed 实现底部导航
通过 position:fixed 实现底部导航 HTML <div id="footer">页脚</div> CSS #footer { clear: b ...
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)
Super Jumping! Jumping! Jumping!Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- BeautifulSoup随笔
BeautifulSoup是一个类 b = BeautifulSoup(html) b对象有与html结构相关的各种方法和和属性. a = b.findAll('a')获得标签的对象 a对象又有关于属 ...
- linux图形界面 KDE、GNOME
1.Linux图形桌面系统组成(由上往下层次结构) 窗口管理器——Enlightenmen.icewm.Fvwm.window-maker 桌面环境———Gnome.KDE.CDE X WINDOW— ...