Problem 2111 Min Number
Accept: 925 Submit: 1838
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
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
map<string, int>m;
string s;
int M; void swap(string &s,int i,int j) {
char tmp = s[i];
s[i] = s[j];
s[j] = tmp;
} string bfs(string &s) {
m.insert(make_pair(s,));
queue<string>que;
que.push(s);
string MIN_num = s;
while (!que.empty()) {
string str = que.front();
if (m[str] == M)break;
que.pop();
for (int i = ; i < s.size();i++) {
for (int j = i + ; j < s.size(); j++) {
string tmp = str;
swap(tmp, i, j);
map<string,int>::iterator it = m.find(tmp);
if (it == m.end()&&tmp[]!='') {
que.push(tmp);
m.insert(make_pair(tmp,m[str]+));
if (MIN_num > tmp) {
MIN_num = tmp;
}
}
}
}
}
return MIN_num;
} int main() {
int T;
scanf("%d",&T);
while (T--) {
cin >> s;
scanf("%d",&M);
m.clear();
cout << bfs(s) << endl;;
}
return ;
}
Problem 2111 Min Number的更多相关文章
- foj 2111 Problem 2111 Min Number
Problem 2111 Min Number Accept: 1025 Submit: 2022Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- fzu 2111 Min Number
http://acm.fzu.edu.cn/problem.php?pid=2111 Problem 2111 Min Number Accept: 572 Submit: 1106Tim ...
- (Problem 28)Number spiral diagonals
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...
- (Problem 17)Number letter counts
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + ...
- HDU Problem D [ Humble number ]——基础DP丑数序列
Problem D Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
- FZOJ2111:Min Number
Problem Description Now you are given one non-negative integer n in 10-base notation, it will only c ...
- Codeforces Round #427 (Div. 2) Problem B The number on the board (Codeforces 835B) - 贪心
Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...
- LeetCode Problem 9:Palindrome Number回文数
描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...
- [LeetCode&Python] Problem 202. Happy Number
Write an algorithm to determine if a number is "happy". A happy number is a number defined ...
随机推荐
- linux - 权限解析
当你在linux下用命令ll 或者ls -la的时候会看到这些字眼,这些字眼表示为不同用户组的权限:r:read就是读权限 --数字4表示w:write就是写权限 --数字2表示 x:excute就是 ...
- c#和Java中的多态
多态:让一个对象表现出多种类型,写出通用的代码,最大限度的屏蔽各个子类之间的差异性. c#举例: 将父类的方法标记为虚方法 ,使用关键字 virtual,这个函数可以被子类重新写一个遍. //真的鸭子 ...
- Apache超时配置
Apache超时配置 1. KeepAliveTimeout 语法 KeepAliveTimeout seconds 默认 5 上下文 server config, virtual host 说明 服 ...
- iOS--获取文件目录的方法
很多文章都有写这个问题,我只是为了记录一下,免得总翻书... 1.Documents 目录: 你应该将所有的应用程序数据文件写入到这个目录下.这个目录用于存储用户数据或其它应该定期备份的信息. 2.L ...
- mysql数据库使用mybatis 插入数据时返回主键
为了体现题目,特指的是mysql,先贴上代码: <insert id="saveBizProdOrderDetail" useGeneratedKeys="true ...
- 【Linux】开放指定端口设置
这里以开放tomcat的8080端口为例 1.开放Linux的8080端口 vi /etc/sysconfig/iptables 进入编辑页面,在指定位置新增以下配置 -A INPUT -m stat ...
- vue里的数据
背景: 一个项目完工在即,鉴于此,前端使用了vue,写下此栏,以供日后翻阅, 会涉及到我所运用到的vue相关知识,需要一定的js基础. 默认vue的single-file-components(单文件 ...
- Python PycURL的安装使用
PycURL中文简介:https://blog.csdn.net/qq_41185868/article/details/80487014 PycURL英文简介(如下):http://pycurl.i ...
- poj 3187 三角数问题
题意:给你两个数,一个n表示这个三角有多少层,一个sum表示总和 思路: 类似杨辉三角 1 1 1 1 2 1 第n行的第k个数 为 n!/k!(n-k)! 暴力枚举,因 ...
- re--参考手册
表达式全集 字符 描述 \ 将下一个字符标记为一个特殊字符.或一个原义字符.或一个向后引用.或一个八进制转义符.例如,“n”匹配字符“n”.“\n”匹配一个换行符.串行“\\”匹配“\”而“\(”则匹 ...