Codeforces 435 B Pasha Maximizes【贪心】
2015-04-20 22:46
274 查看
题意:给出一串数字,给出k次交换,每次交换只能交换相邻的两个数,问最多经过k次交换,能够得到的最大的一串数字
从第一个数字往后找k个位置,找出最大的,往前面交换
有思路,可是没有写出代码来---sad
View Code
从第一个数字往后找k个位置,找出最大的,往前面交换
有思路,可是没有写出代码来---sad
#include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include<set> #include<queue> #include<algorithm> using namespace std; typedef long long LL; const int INF = (1<<30)-1; const int mod=1000000007; const int maxn=100005; char s[maxn]; int main(){ int k; cin>>s; cin>>k; int best; int len=strlen(s); for(int i=0;i<len;i++){ best=i; for(int j=i+1;j<=i+k&&j<len;j++){ if(s[j]>s[best]){ best=j; } } if(best!=i){ for(int j=best;j>i;j--){ swap(s[j],s[j-1]); k--; } } } printf("%s\n",s); return 0; }
View Code
相关文章推荐
- Codeforces 435B Pasha Maximizes(贪心)
- Codeforces Round #249 (Div. 2)B Pasha Maximizes(贪心)
- Codeforces Round #249 (Div. 2)B Pasha Maximizes(贪心)
- 【23.33%】【codeforces 557B】Pasha and Tea
- codeforces 651A Joysticks【贪心】
- Codeforces--615B--Longtail Hedgehog(贪心模拟)
- Codeforces 337C Quiz 贪心+快速幂
- CodeForces 732D Exams 二分+贪心
- CodeForces - 731C Socks (并查集+贪心)
- codeforces 222D Olympiad(贪心)
- CodeForces 489C Given Length and Sum of Digits... (贪心)
- Codeforces 791 C. Bear and Different Names【贪心】
- Codeforces 363D Renting Bikes【二分+贪心】
- 【Codeforces 733D】 Kostya the Sculptor【贪心】
- codeforces 337E E. Divisor Tree(数论+贪心)
- CodeForces - 620C Pearls in a Row |set,贪心
- CodeForces 698A Vacations(贪心)
- Codeforces 701E Connecting Universities 贪心
- Codeforces 401A Vanya and Card【贪心】水题
- Codeforces 388A Fox and Box Accumulation(贪心)