http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1181
来源:互联网 发布:nodejs mysql建模 编辑:程序博客网 时间:2024/05/17 21:47
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?
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.
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 43212311 4
12111法一:采用贪心策略,每次删除单调递减的第一个字符。
#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
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1001&&纸牌游戏
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1003&&矩阵链乘
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1187&&Hole Breaker
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1186
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1184&&Elaine's Queue
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1182&&Counter-Strike
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1180
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1198&& I can do it!
- Enumerate the Triangles&&http://cdn.ac.nbutoj.com/Contest/view/id/14/problem/E.xhtml
- http://acm.nbut.cn:8081/Problem/view.xhtml?id=1317&&线段树单点查询
- Anger Begins&&http://acm.nbut.cn:8081/Contest/view/id/29/problem/A.xhtml
- C函数传递结构体指针 题目地址:http://ac.jobdu.com/problem.php?id=1061
- http://ac.jobdu.com/problem.php?pid=1008
- http://ac.jobdu.com/problem.php?pid=1009
- http://ac.jobdu.com/problem.php?pid=1007
- http://ac.jobdu.com/problem.php?pid=1033
- http://ac.jobdu.com/problem.php?pid=1005
- Eclipse开发PHP调试(debug)环境配置
- 展销一批计算机及各类书籍外加望远镜130826
- IOS 播放音乐实例
- 购物车的代码
- C语言详解 - 枚举类型
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1181
- 我的博客有自己的独立域名了
- 推荐一本书《java夜未眠》
- IOS处理音乐播放中断实例
- IOS 定时器NSTimer的使用
- 禅设计模式
- boost学习之-scoped_array
- 【学习笔记】DM9000裸机驱动(三)之简单ARP协议的实现
- 3T硬盘(GPT分区)支持