coeforces 628C. Bear and String Distance
来源:互联网 发布:工程网络计划图 编辑:程序博客网 时间:2024/06/10 19:04
题意: 给一个字符串S,和 K 两个字符的dis == 其ASCII 码值得绝对值,
要求构造一个字符串S1是的sum = dis(S[i] - S1[i]) (i=0,,1 ,,,,,n ,) ==k ;
思路: 贪心,使得前面以最大差出现,后面保持一致即可
#include<bits/stdc++.h>using namespace std;string s,s1;int main(){ int n,m; scanf("%d%d",&n,&m); cin>>s; for(int i =0; i<s.length(); i++) { if(m==0) { s1+= s[i]; continue; } int x = s[i]-'a'; int y = 'z' - s[i]; if(x>y) { if(m>=x) { s1 += 'a'; m-=x; } else { s1+= s[i]-m; m = 0; } } else { if(m>=y) { s1+='z'; m-=y; } else { s1+=s[i]+m; m = 0; } } } if(m!=0) { cout<<"-1\n"<<endl; return 0; } cout<<s1<<endl;}
0 0
- coeforces 628C. Bear and String Distance
- codeforces 628C Bear and String Distance
- CodeForces 628C - Bear and String Distance
- CodeForces 628C Bear and String Distance
- CodeForces 628 C C - Bear and String Distance
- Codeforces 628C Bear and String Distance 【构造】
- CodeForces 628 C. Bear and String Distance(贪心)
- CodeForces 628C Bear and String Distance (水题)
- 【CodeForces 628C 】Bear and String Distance (贪心)
- CodeForces - 628C Bear and String Distance (模拟)
- Codeforces 628 C. Bear and String Distance【贪心】
- codeforces 628C Bear and String Distance 水
- Codeforces C - Bear and String Distance (贪心)
- codeforces_628C. Bear and String Distance
- Educational Codeforces Round 8 C. Bear and String Distance(贪心)
- Bear and Polynomials 639 C
- C. Bear and Different Names
- Codeforces 385 C. Bear and Prime Numbers
- centos6.5编译rpm源码
- 删除mac上的插件教程
- Service和activty交互方式
- Java中的静态绑定和动态绑定
- Android最佳性能实践(一)——合理管理内存
- coeforces 628C. Bear and String Distance
- iOS 设置导航条的主题
- jasoncpp在visual studio下的编译和使用
- Android Interface Definition Language (AIDL)
- 【Bugly干货分享】iOS内存管理:从MRC到ARC实践
- Servlet过滤器和监听器知识总结
- Android优化Adapter内的Click、LongClick
- MySQL常用命令
- Retrofit 2.0 + OkHttp 3.0 配置