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 ...
随机推荐
- Apache Jmeter进行服务器压力测试
1.前言 最近项目遇到一个问题:其他公司对接我们系统,请求量太大的时候,返回单给对方就是丢失格式,大概十几万中总有那么十几单会出现格式错误! 所以我们老大就叫我用apache jmeter来进行并发测 ...
- 推荐Java五大微服务器及其代码示例教程
来源素文宅博客:http://blog.yoodb.com/yoodb/article/detail/1339 微服务越来越多地用于开发领域,因为开发人员致力于创建更大,更复杂的应用程序,这些应用程序 ...
- [LC]237题 Delete Node in a Linked List (删除链表中的节点)(链表)
①中文题目 请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点. 现有一个链表 -- head = [4,5,1,9],它可以表示为: 示例 1: 输入: hea ...
- DAL
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data;u ...
- VLAN实验(4)单臂路由
1.选择1台Router路由器.2台S3700交换机和4台pc机,并根据实验编址完成此拓扑图. 2.对交换机mengyu-S2建立VLAN (1)建立两个VLAN,VLAN10和VLAN20,并添加描 ...
- shell脚本1——变量 $、read、``
与Shell变量相关的几个命令: 变量只在当前Shell中生效. source 这个命令让脚本影响他们父Shell的环境(. 可以代替source命令) export 这个命令可以让脚本影响其子She ...
- Docker基础与实战,看这一篇就够了
docker 基础 什么是Docker Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 Linux 内核的 cgroup,namespace,以及 AUFS 类的 Uni ...
- 神奇的 SQL 之 MySQL 性能分析神器 → EXPLAIN,SQL 起飞的基石!
前言 开心一刻 某人养了一头猪,烦了想放生,可是猪认识回家的路,放生几次它都自己回来了.一日,这个人想了个狠办法,开车带着猪转了好多路进山区放生,放生后又各种打转,然后掏出电话给家里人打了个电话,问道 ...
- 小白学习React官方文档看不懂怎么办?
最近在上React课程的时候,发现好多同学不会看文档,所以在这里写一篇文章,希望能给同学们一点点启发. 我们首先打开React官方网站——https://react.docschina.org/doc ...
- 护网杯2019 mergeheap --pwn
护网 又是签到 一天 这道题一开始 不懂得如何泄露 libc 信息,就蒙了 后来群里师傅也是刚刚好 做出 到这里 我就接着做了 . 先看下保护,发现 全开了 然后 就看下流程 大概 就是添加 c ...