SRM 437 TheSwap ( Permutation + Memory Search )
来源:互联网 发布:手机淘宝店简介怎么写 编辑:程序博客网 时间:2024/05/29 17:40
My idea:
At first I solve this problem with the greedy approach (keeping the number maximal for every iteration) and all the test cases given is right . Later on I find some cases from the discussion that my code gives the wrong answer .
For example : 35766 3
the correct result is that 35766->75366->76356->76653
but the greedy approach works like this : 35766->75366->76365->76635
Here I will use the make permutation and memory search to solve this problem , and I have learn much about STL in C++ this time .
Problem Statement
There is nothing more beautiful than just an integer number.
You are given an integer n. Write down n in decimal notation with no leading zeroes, and let M be the number of written digits. Perform the following operation exactly k times:
- Choose two different 1-based positions, i and j, such that 1 <= i < j <= M. Swap the digits at positions i and j. This swap must not cause the resulting number to have a leading zero, i.e., if the digit at position j is zero, then i must be strictly greater than 1.
Return the maximal possible number you can get at the end of this procedure. If it's not possible to perform k operations, return -1 instead.
Definition
Class:TheSwapMethod:findMaxParameters:int, intReturns:intMethod signature:int findMax(int n, int k)(be sure your method is public)Constraints
-n will be between 1 and 1,000,000, inclusive.-k will be between 1 and 10, inclusive.
- SRM 437 TheSwap ( Permutation + Memory Search )
- 排列问题 permutation(似乎原题是SRM 592 Little Elephant And Permutation Div1?)
- Elastic Search increase memory/heap
- srm
- In Search of Memory, in search of myself
- 31. Next Permutation \ 33. Search in Rotated Sorted Array
- LeetCode 31.Next Permutation & 33.Search in Rotated Sorted Array
- Permutation
- Permutation
- permutation
- Permutation
- Permutation
- Permutation
- permutation
- Permutation
- permutation
- Permutation
- Permutation
- ThreadLocal是什么
- 新手问题
- 公关公司工作委员会09年工作会议在京召开
- 内核编程笔记
- SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
- SRM 437 TheSwap ( Permutation + Memory Search )
- 中间件
- vc++开发http应用
- 使用Log4j记录系统日志(转载)
- 怎么看sql2000端口是多少啊
- Custom redirect after login
- linux内核----- swtich_to 详细分析
- VC++实现局域网嗅探QQ号
- 系统总线、I/O总线区别