题意:给出一串数字,给出k次交换,每次交换只能交换相邻的两个数,问最多经过k次交换,能够得到的最大的一串数字

从第一个数字往后找k个位置,找出最大的,往前面交换

有思路,可是没有写出代码来---sad

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=;
char s[maxn]; int main(){
int k;
cin>>s;
cin>>k;
int best;
int len=strlen(s);
for(int i=;i<len;i++){
best=i;
for(int j=i+;j<=i+k&&j<len;j++){
if(s[j]>s[best]){
best=j;
}
} if(best!=i){
for(int j=best;j>i;j--){
swap(s[j],s[j-]);
k--;
} }
}
printf("%s\n",s);
return ;
}

Codeforces 435 B Pasha Maximizes【贪心】的更多相关文章

  1. codeforces 435 B. Pasha Maximizes 解题报告

    题目链接:http://codeforces.com/problemset/problem/435/B 题目意思:给出一个最多为18位的数,可以通过对相邻两个数字进行交换,最多交换 k 次,问交换 k ...

  2. CF 435B Pasha Maximizes(贪心)

    题目链接: [传送门][1] Pasha Maximizes time limit per test:1 second     memory limit per test:256 megabytes ...

  3. Codeforces 435B. Pasha Maximizes

    简单贪心.... B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  5. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  6. Codeforces Round #249 (Div. 2) B. Pasha Maximizes

    看到题目的时候,以为类似插入排序,比较第i个元素和第i-1个元素, 如果第i个元素比第i-1个元素小,则不交换 如果第i个元素比第i-1个元素大,则交换第i个元素和第i-1个元素 继续比较第i-1个元 ...

  7. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  8. Codeforces Gym 100269E Energy Tycoon 贪心

    题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...

  9. CodeForces 797C Minimal string:贪心+模拟

    题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...

随机推荐

  1. HDU 1397 Goldbach's Conjecture(二分,查找素数)

    题目意思很简单,就是找n=p1+p2的种类数,具体看题目吧. 次重点是查找一定范围内的素数: 重点是用二分查找,不然会超时!!! #include<stdio.h> #include< ...

  2. UITextField输入中文限制

      [self.textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEve ...

  3. POJ 1477

    #include <iostream> #define MAXN 100 using namespace std; int _[MAXN]; int main() { //freopen( ...

  4. sql server 数据库 数据DateTime 转mysql

    首先将sql server  DateTime 转换为varchar(50) 然后更新转换过的 DateTime字段, UPDATE 表名 SET LastUpdateTime=CONVERT(VAR ...

  5. System.getProperty()参数

    java.version Java 运行时环境版本 java.vendor Java 运行时环境供应商 java.vendor.url Java 供应商的 URL java.home Java 安装目 ...

  6. mysql 死锁检查

    今天看了一篇关于死锁检查的blog. Advanced InnoDB Deadlock Troubleshooting – What SHOW INNODB STATUS Doesn’t Tell Y ...

  7. 解决安装rpm时lib冲突:libstdc++-2-libc6.1-1-2.9.0.so from install of compat-libstdc++-7.3-2.96.118 conflicts with file from ...

    sudo rpm -ivh xxx.rpm -aid --force [oracle@localhost Oracle]$ .i386.rpm compat-libstdc++-devel-.i386 ...

  8. lintcode:Wiggle Sort

    Wiggle Sort Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= ...

  9. LR_问题_平均响应时间解释,summary与analysis不一致

    Summary Report中的时间说明 Summary是按整个场景的时间来做平均的,最大最小值,也是从整个场景中取出来的. (1)       平均响应时间:事物全部响应时间做平均计算 (2)    ...

  10. java jms

    这篇博文我们主要介绍J2EE中的一个重要规范JMS,因为这个规范在企业中的应用十分的广泛,也比较重要,我们主要介绍JMS的基本概念和它的模式,消息的消费以及JMS编程步骤. 基本概念 JMS是java ...