foj 2111 Problem 2111 Min Number
Accept: 1025 Submit: 2022
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
after no more than M operations.
Sample Input
9012 0
9012 1
9012 2
Sample Output
1092
1029
#include <iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
#include<string>
using namespace std;
#define N_MAX 10000+10
#define V_MAX 1000+10
#define INF 0x3f3f3f3f
int m;
string n;
void change(string &s,int n){//当前调整s的第n位
char c=''+;int id;
for(int i=s.size()-;i>n;i--){
if(c>s[i]){
if(n==&&s[i]=='')continue;
c=s[i];id=i;
}
}
if(c<s[n])swap(s[n],s[id]);
}
int main(){
int t;scanf("%d",&t);
while(t--){
cin>>n>>m;
int cnt=;
string s;
while(m){
s=n;
while(s==n&&cnt<s.size()-){
change(n,cnt);
cnt++;
}
if(cnt>=s.size()-)break;//已经不需要交换了
m--;
}
cout<<n<<endl;
}
return ;
}
foj 2111 Problem 2111 Min Number的更多相关文章
- fzu 2111 Min Number
http://acm.fzu.edu.cn/problem.php?pid=2111 Problem 2111 Min Number Accept: 572 Submit: 1106Tim ...
- Problem 2111 Min Number
...
- (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 ...
- FOJ题目Problem 2082 过路费 (link cut tree边权更新)
Problem 2082 过路费 Accept: 382 Submit: 1279 Time Limit: 1000 mSec Memory Limit : 32768 KB Proble ...
随机推荐
- 处理侧滑返回与 ScrollView 手势冲突
与处理双击.单击手势互斥原则一样: // 手势互斥(侧滑返回手势失效后才响应UITableView的滑动手势) [tableView.panGestureRecognizer requireGestu ...
- CentOS7安装Nginx、MySQL、PHP
之前才网上找了好多文章,但是配置总会出错,后来傻傻的发现官方文档都有的,当然配合网上文章说明更好,因此本文只说一个大概 安装PHP 官方配置 配置用户和用户组,需要有根目录权限 vim /usr/lo ...
- js禁止微信浏览器下拉显示黑底查看网址
// 首先禁止body document.body.ontouchmove = function (e) { e.preventDefault(); }; // 然后取得触摸点的坐标 var star ...
- U盘装系统之winpe中常用安装win7的方法和备份(2013-01-15-bd 写的日志迁移
首先到网上去下一个制作U盘启动的的软件比如老毛桃.大白菜.电脑城制作u盘启动软件[其实他们的装机界面和工具那些都差不多], 我是用的老毛桃至于制作流程你可以看它的视频你往下拉就可以看见,或者看说明,自 ...
- 如何提高STM32的学习效率
时间如何安排 做任何事情前,习惯写一个计划——要在一个月内上手STM32! 没有计划的日子,每天早上醒来睁开眼睛,却不知道自己今天要干啥 计划和时间安排: 第一阶段:找感觉——谈及STM32,立即反应 ...
- sql优化系列3(收集来源http://bbs.csdn.net/topics/250004467)
如何加快查询速度? 1.升级硬件 2.根据查询条件,建立索引,优化索引.优化访问方式,限制结果集的数据量. 3.扩大服务器的内存 4.增加服务器CPU个数 5.对于大的数据库不要设置数据库自动增长 ...
- Androd安全——反编译技术完全解析
)第二步成功后我们会发现在当前目录下多了一个<APKName>文件夹,这个文件夹中存放的就是反编译的结果了.我们可以打开AndroidManifest.xml.res/layout即可查看 ...
- Spring加载配置文件的几种方法(org.springframework.beans.factory.BeanDefinitionStoreException)
一:Spring中的几种容器都支持使用xml装配bean,包括:XmlBeanFactory ,ClassPathXmlApplicationContext ,FileSystemXmlApplica ...
- app分享代码
友推是一款是面向移动应用的SDK分享组件,提供给开发者集成使用.通过友推,开发者可以轻松集成社会化分享功能,同时创建及管理推荐好友使用您应用的推荐奖励活动,用户推荐好友安装使用您的应用即可获得推荐奖励 ...
- 【N-Quens II】cpp
题目: Follow up for N-Queens problem. Now, instead outputting board configurations, return the total n ...