- 问题描述
-
The game LOL is an interesting game. Recently we are playing this game. Once I used a champion named Kog'Maw - The Mouth of the Abyss.
For I have to support teammate, I only have a little time to do the last hit to kill the enemy's minions.
There're N (2 <= N <= 10000) minions, each minion has a threat value TVi (1 <= TVi <= 9).
And there's a formula to calculate the total threat value:
I only can kill K (1 <= K < N) minions.
When I kill one minion, the minions after it will move to front for one step. It means when I kill Minion[5], then Minion[6] will be Minion[5] and Minion[7] will be Minion[6] and so on.
How to kill the minions that I can leave the minimum total threat value? - 输入
-
This problem contains several cases.
Each case contains two numbers. The first number T is the total threat value at the very beginning (1 <= T < 10^10001). Then follows an integer K, means the number that minions I can kill.
- 输出
-
For each case, you should output the minimum total threat value after I kill K minions.
- 样例输入
-
123456 4 3212311 4
- 样例输出
-
12 111
法一:采用贪心策略,每次删除单调递减的第一个字符。 - AC代码:
#include<iostream> #include<string> using namespace std; int main() { string s; int n; while(cin>>s>>n) { for(int i=0;i<n;++i) { for(int j=0;j<s.size();++j) if(j==s.size()-1||s[j]>s[j+1]) { s.erase(s.begin()+j); break; } }cout<<s<<endl; }return 0; }
法二:每次在规定范围内删除最小的字符#include<iostream> #include<string.h> #include<string> using namespace std; string work(string s,int n) { int m=s.size()-n; int first=0,last=n; string s1=""; while(m--) { int minx=9999999,p; for(int i=first;i<=last;++i) if(s[i]<minx) {p=i;minx=s[i];} s1+=minx; first=p+1,last++; }return s1; } int main() { string s; int n; while(cin>>s>>n) { cout<<work(s,n)<<endl; }return 0; }
http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1181
最新推荐文章于 2024-06-25 17:23:30 发布