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 ...
随机推荐
- 六 mybatis高级映射(一对一,一对多,多对多)
1 订单商品数据模型 以订单商品数据为模型,来对mybaits高级关系映射进行学习.
- CDH(Cloudera)与hadoop(apache)对比
本文出自:CDH(Cloudera)与hadoop(apache)对比http://www.aboutyun.com/thread-9225-1-1.html(出处: about云开发) 问题导读 ...
- win环境下,用虚拟化工具打包Qt动态编译exe的过程(使用Enigma Virtual Box)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://goldlion.blog.51cto.com/4127613/834075 引子 ...
- c 生成随机不重复的整数序列
#include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <time.h> ...
- C/C++获取系统时间
C/C++获取系统时间需要使用Windows API,包含头文件"windows.h". 系统时间的数据类型为SYSTEMTIME,可以在winbase.h中查询到如下定义: ty ...
- 导出证书Cer文件为Pem格式的步骤
(1)先导出Push Services的证书,比如我们命名为“magic_cert.p12”,注意导出时会让你输入密码. (2)再导出Push Services证书的密钥(Private Key),比 ...
- How to control printer orientation(Landscape / Portrait) for an AX report in X++
You should try this: 1. Set property Orientation on your report design to Auto 2. In your fetch meth ...
- [LeetCode]题解(python):049-Groups Anagrams
题目来源 https://leetcode.com/problems/anagrams/ Given an array of strings, group anagrams together. For ...
- 导入maven工程并配置maven环境
步骤一 : 选择 "Import"操作 有两个途径可以选择 "Import"操作; 1>"File"--> "Impo ...
- iOS 应用内跳转到appstore里下载
SKStoreProductViewController类是UIViewController的子类, 如果你对view controller比较熟悉的话,那SKStoreProductViewCont ...