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 ...
随机推荐
- 01_11_SERVLET中使用javabean
01_11_SERVLET中使用javabean 1. javabean 广义javabean = 普通java类 狭义javabean = 符合 Sun JavaBean标准的类 在Servlet中 ...
- Java动画 重力弹球 如鹏游戏引擎 精灵 设计一个小球加速落地又减速弹起并反复直到停止的Java程序
package com.swift; import com.rupeng.game.GameCore; public class BouncingBall implements Runnable { ...
- cocos2dx 使用XMLHttpRequest时回调status为0的问题
今天使用cocos连接http访问时,使用XMLHttpRequest在pc上反问时正常的返回了status=0,但是在android上去返回status是0,看了一下底层代码, 发现status只有 ...
- dSYM文件
来到新公司后,前段时间就一直在忙,前不久 项目 终于成功发布上线了,最近就在给项目做优化,并排除一些线上软件的 bug,因为项目中使用了友盟统计,所以在友盟给出的错误信息统计中能比较方便的找出客户端异 ...
- 记住密码功能 JS结合JQuery 操作 Cookie 实现记住密码和用户名!
// 记住密码功能 JS结合JQuery 操作 Cookie 实现记住密码和用户名! var username = document.getElementById("username&quo ...
- 66. Plus One@python
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...
- [LUOGU] 4149 [IOI2011]Race
点分治裸题 #include<iostream> #include<cstring> #include<cstdio> using namespace std; i ...
- mysql 在线添加字段
使用工具pt-online-schema-change #! /bin/bash stime=`date +%s` echo "增加字段开始测试时间为:`date +%H:%M:%S`&qu ...
- Struts2和Spring MVC 区别 今天面试被问到了
虽然说没有系统的学习过Spring MVC框架, 但是工作这么长时间, 基本上在WEB层使用的都是Spring MVC, 自己觉得Struts2也是一个不错的WEB层框架, 这两种框架至今自己还未有比 ...
- Python 基本数据类型 (二) - 字符串1
# ----------- 首字母大写 ---------- test = "alex is a man" v = test.capitalize() print(v): Alex ...