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 ...
随机推荐
- 文档对象模型 DOM
1 DOM概述 1.1 什么是DOM 文档对象模型 Document Object Model 文档对象模型 是表示和操作 HTML和XML文档内容的基础API 文档对象模型,是W3C组织推荐的处理可 ...
- 如何修改iframe内的页面的元素的样式。。。。
方法一: 直接通过设置backgroundColor的颜色即可:<!DOCTYPE html><html><head><script>function ...
- 【Python】剑指offer 14:剪绳子
题目:给你一根长度为n的绳子,请把绳子剪成m段 (m和n都是整数,n>1并且m>1)每段绳子的长度记为k[0],k[1],-,k[m].请问k[0]k[1]-*k[m]可能的最大乘积是多少 ...
- Elizabeth Taylor【伊丽莎白·泰勒】
Elizabeth Taylor People fell in love with Elizabeth Taylor in 1944, when she acted in the movie Nati ...
- B1007 素数对猜想
B1007 素数对猜想 让我们定义\(d_n\)为:\(d_n =p_{n+1}−p_n\),其中\(p_i\)是第i个素数.显然有\(d_1=1\),且对于n>1有\(d_n\)是偶数.&qu ...
- A1009 Product of Polynomials (25)(25 分)
A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...
- (洛谷)P1019 单词接龙
题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的"龙"(每个单词都最多在"龙" ...
- POJ3320 尺取法的正确使用法
一.前言及题意: 最近一直在找题训练,想要更加系统的补补思维,补补漏洞什么的,以避免被个类似于脑筋急转弯的题目干倒,于是在四处找书,找了红书.蓝书,似乎都有些不尽如人意.这两天看到了日本人的白书,重新 ...
- UVA 10859 Placing Lamppost 树形DP+二目标最优解的求解方案
题意:给定一个无向,无环,无多重边,要求找出最少的若干点,使得,每条边之中至少有一个点上有街灯.在满足上述条件的时候将还需要满足让两个点被选择的边的数量尽量多. 题解: 对于如何求解最小的节点数目这点 ...
- Java面向对象---抽象类与接口
final关键字 1.final关键字在java中被称为完结器,表示最终的意思: 2.final能声明类.方法.属性: 3.使用final声明的类不能被继承,使用final声明的方法不能被重写,使用f ...