fzu 2111 Min Number

Accept: 572 Submit: 1106
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, here |n| means the length of n’s 10-base notation. Then we can swap n[i] and n[j].
For example, n=9012, we choose i=1, j=3, then we swap n[1] and n[3], then we get 1092, which is smaller than the original n.
Now you are allowed to operate at most M times, so what is the smallest number you can get after the operation(s)?
Please note that in this problem, leading zero is not allowed!
Input
The first line of the input contains an integer T (T≤100), indicating the number of test cases.
Then T cases, for any case, only 2 integers n and M (0≤n<10^1000, 0≤M≤100) in a single line.
Output
Sample Input
Sample Output
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue> using namespace std; const int INF = 0x3f3f3f3f;
const int MAX = + ;
const double eps = 1e-;
const double PI = acos(-1.0); char str[MAX];
int len; int judge(int n)
{
int temp = n , i;
if(n == )
{
char min = str[n];
for(i = ;i < len;i ++)
{
if(str[i] != '' && str[i] <= min)
{
min = str[i];
temp = i;
}
}
}
else
{
char min = str[n];
for(i = n + ;i < len ;i ++)
{
if(str[i] <= min)
{
min = str[i];
temp = i;
}
}
}
return temp;
} int main()
{
int T , n;
scanf("%d",&T);
while(T --)
{
scanf("%s %d",str , &n);
len = strlen(str);
int i = ;
while(n --)
{
int ji = judge(i);
if(ji == i)
{
n ++;
i ++;
}
else
{
str[i] = (str[ji] ^ str[i] ^ (str[ji] = str[i]));
i ++;
}
if(i == len)
break;
}
for(i = ;i < len ;i ++)
printf("%c",str[i]);
puts("");
}
return ;
}
fzu 2111 Min Number的更多相关文章
- foj 2111 Problem 2111 Min Number
Problem 2111 Min Number Accept: 1025 Submit: 2022Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- Problem 2111 Min Number
...
- FZU 2102 Solve equation(水,进制转化)&& FZU 2111(贪心,交换使数字最小)
C Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pra ...
- FZU 1649 Prime number or not米勒拉宾大素数判定方法。
C - Prime number or not Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- FZOJ2111:Min Number
Problem Description Now you are given one non-negative integer n in 10-base notation, it will only c ...
- FZU - 2109 Mountain Number 数位dp
Mountain Number One integer number x is called "Mountain Number" if: (1) x>0 and x is a ...
- FZU 2109 Mountain Number
http://acm.fzu.edu.cn/problem.php?pid=2109 题意:找出区间[l,r]内满足奇数位的数字大于相邻偶数位数字的个数. 典型的数位dp了,记录一下当前位是奇数位还是 ...
- FZU Problem 1853 Number Deletion
Problem 1853 Number Deletion Accept: 80 Submit: 239 Time Limit: 1000 mSec Memory Limit : 32768 ...
- FZU——2111Min Number(多次交换得到最小数,水题)
Problem 2111 Min Number Accept: 760 Submit: 1516 Time Limit: 1000 mSec Memory Limit : 32768 KB ...
随机推荐
- Lazarus中system.length说明
在system单元中我们有Length专门用来获取字符串宽度和数组宽度,下面例子来介绍他的功能. 定义: function Length( S: AStringType ):Integer; fu ...
- transform animation transition css3动画
transform 定义 transform 属性向元素应用 2D 或 3D 转换.该属性允许我们对元素进行旋转.缩放.移动或倾斜. 值 应用 如果transform与transition联合起 ...
- Bootstrap 输入框和导航组件
一.输入框组件 //在左侧添加文字 <div class="input-group"> <span class="input-group-addon&q ...
- 关于<a href='javascript:function()'>
<a href='javascript:function()'> 这样写是为了让这个链接不要链接到新页面转而执行一段js代码.和onclick能起到同样的效果,一般来说,如果要调用脚本还是 ...
- php源码安装
要用swoole,首先需要有PHP环境.由于swoole的某些特性,最好是能够从源码编译安装PHP,这样在使用过程中可以避免很多不必要的错误.PHP下载地址:http://php.net/在这里挑选你 ...
- jQuery EasyUI---validatebox 校验规则扩展
EasyUI 的 validatebox 插件, 验证规则相对比较单一也比较少,如下. rules: { email:{ validator: function(value){ return ...? ...
- Erlang ERTS的Trap机制的设计及其用途
出处:http://mryufeng.iteye.com/blog/334744 erlang的trap机制在实现中用的很多,在费时的BIF操作中基本上都可以看到.它的实现需要erl vm的配合.它的 ...
- ligerui多选动态下拉框
今天下午要求做一个支持多选的,并且插件用ligerui的,当时有点小懵了,因为没用过ligerui啊!而且按照API的介绍,我做得也很好啊,可是为什么就是显示不出来?据说有位小神比较厉害,请教来之,两 ...
- windows2008一键安装环境的配置说明
windows 2008 一键安装包下载地址为 http://gongdan.oss-cn-hangzhou.aliyuncs.com/market/cmISV/34320/product/cmgj0 ...
- Sqlcompletefree
Sqlcompletefree SQLSERVER中SQL代码自动提示填充,自动格式化SQL语句工具Sqlcompletefree.方便开发操作.