Codeforces 435B. Pasha Maximizes
简单贪心....
1 second
256 megabytes
standard input
standard output
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only
operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).
Print the maximum number that Pasha can get if he makes at most k swaps.
1990 1
9190
300 0
300
1034 2
3104
9090000078001234 6
9907000008001234
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; char str[200];
int nt; int main()
{
long long int a;
int k;
cin>>a>>k;
while(a)
{
str[nt++]=a%(10LL)+'0';
a/=10LL;
}
for(int i=nt-1;i>=0&&k;i--)
{
int mark=-1,dist=-1;
for(int j=i;j>=max(0,i-k);j--)
{
if(str[j]>str[mark])
{
mark=j; dist=i-j;
}
}
k-=dist;
for(int j=mark;j<i;j++)
{
swap(str[j],str[j+1]);
}
}
for(int i=nt-1;i>=0;i--)
{
cout<<str[i];
}
cout<<endl;
return 0;
}
Codeforces 435B. Pasha Maximizes的更多相关文章
- CF 435B Pasha Maximizes(贪心)
题目链接: [传送门][1] Pasha Maximizes time limit per test:1 second memory limit per test:256 megabytes ...
- codeforces 435 B. Pasha Maximizes 解题报告
题目链接:http://codeforces.com/problemset/problem/435/B 题目意思:给出一个最多为18位的数,可以通过对相邻两个数字进行交换,最多交换 k 次,问交换 k ...
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
看到题目的时候,以为类似插入排序,比较第i个元素和第i-1个元素, 如果第i个元素比第i-1个元素小,则不交换 如果第i个元素比第i-1个元素大,则交换第i个元素和第i-1个元素 继续比较第i-1个元 ...
- Codeforces 435 B Pasha Maximizes【贪心】
题意:给出一串数字,给出k次交换,每次交换只能交换相邻的两个数,问最多经过k次交换,能够得到的最大的一串数字 从第一个数字往后找k个位置,找出最大的,往前面交换 有思路,可是没有写出代码来---sad ...
- codeforces 557B. Pasha and Tea 解题报告
题目链接:http://codeforces.com/problemset/problem/557/B 题目意思:有 2n 个茶杯,规定第 i 个茶杯最多只能装 ai 毫升的水.现在给出 w 毫升的水 ...
- Codeforces 595B - Pasha and Phone
595B - Pasha and Phone 代码: #include<bits/stdc++.h> using namespace std; #define ll long long # ...
- Codeforces 595B. Pasha and Phone 容斥
B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- codeforces B. Pasha and String
Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters ...
- codeforces B. Pasha and String(贪心)
题意:给定一个长度为len的字符序列,然后是n个整数,对于每一个整数ai, 将字符序列区间为[ai,len-ai+1]进行反转.求出经过n次反转之后的序列! /* 思路1:将区间为偶数次的直接去掉!对 ...
随机推荐
- Sharepoint 2013 启用搜做服务
参考文件: http://www.cnblogs.com/jianyus/archive/2013/02/04/2891801.html 1. 创建好网站集,进入网站内容,点击搜素,会出现如下错误:( ...
- 转换GridView的内容到Excel里面 ---带有格式
http://www.aspsnippets.com/Articles/Export-GridView-to-Excel-in-ASPNet-with-Formatting-using-C-and-V ...
- [译]在 64bit 环境中执行32 bit的SSIS包
最近碰到了一个众所周知的32bit的 SSIS 包在64bit的SQL Server环境的执行问题. 我看了一些解决方案,比如修改在SSDT里面修改 debug 选项(Run64BitRuntime ...
- javascript对象属性——数据属性和访问器属性
ECMA-262第五版在定义时,描述了属性property的各种特征,定义这些特性是为了实现javascript引擎用的,为了表示该特性是内部值,规范把它们放在了两对儿方括号中,例如[[Enumera ...
- C - N皇后问题(搜索)
Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上. 你的任务是,对于给定的N,求出有多少种合 ...
- c语言: 文件io, 拷贝文件(二进制)
#include <stdio.h> #include <stdlib.h> #define TRAN_SZIE 1024 int copy_bin(char* from, c ...
- Eclipse之报错信息及其解决方案
一.有很多人都喜欢开发js的时候用aptana,因此在eclipse中集成aptana插件是必须的,可是,在用link方式在eclipse中安装好aptana后,启动时会报如下错误 An intern ...
- HTML5 音频视频
HTML5 视频和音频的 DOM 参考手册 HTML5 DOM 为 <audio> 和 <video> 元素提供了方法.属性和事件. 这些方法.属性和事件允许您使用 JavaS ...
- windos下安装PEAR 注意
1.在这里下载PEAR http://pear.php.net/go-pear.phar 在页面右键另存为 go-pear.phar 到PHP的根目录,并去目录查看是否保存为了go-pear.phar ...
- A package manager for Qt
官网 http://www.qpm.io/ A package manager for Qt 注释:这个网站类似JavaScript的包管理器的网站https://www.npmjs.com/ 都是给 ...