CF Gym 字符串字典序
来源:互联网 发布:机场免税店mac价格 编辑:程序博客网 时间:2024/04/29 09:13
点击打开链接
#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>using namespace std;const int M=1e5+20;char a[M];int n;int pos[27];//字符出现的最早位置 int main(){int t;cin>>t;while(t--){ char c1,c2;scanf("%s",a);n=strlen(a);memset(pos,0x3f3f3f3f,sizeof(pos));for(int i=0;i<n;i++){//操作 //replace all occurrences of the first letter you chose with the second one, //and replace all occurrences of the second letter you chose with the first one. //使得字典序尽量小 //所以从靠前字符开始考虑 与它之后的最小字符互换(最小字符不能出现在它之前)//因为是全部互换 防止互换后变大 :abccac交换后为baccbc显然不符合 pos[a[i]-'a']=min(pos[a[i]-'a'],i);//所以记录字符出现的最早位置 }int flag;for(int i=0;i<n;i++)//复杂度为O(26*n) {flag=0;for(int k=0;k<a[i]-'a';k++)//只由小写字符组成 {if(pos[k]!=0x3f3f3f3f&&pos[k]>pos[a[i]-'a']){flag=1;c1=a[i];c2=k+'a';break;}}if(flag)break;}if(flag)for(int i=0;i<n;i++){if(a[i]==c1){a[i]=c2;}else if(a[i]==c2){a[i]=c1;}}printf("%s\n",a);}return 0;}
0 0
- CF Gym 字符串字典序
- cf Gym
- CF GYM 100741 A Queries
- 字典序字符串
- gym 100935B (字典树)
- CF 496C(Removing Columns-贪心取字典序)
- CF Gym 100227 I题 题解
- CF gym Coins(01背包计数)
- [CF Gym 100372C] Sergey and array
- [CF Gym 100372E] Sergey’s game
- CF gym: Feel Good(单调栈)
- cf Gym 101086F Hey JUDgE
- 字符串按照字典序排序
- 字符串的排列(字典序)
- 字符串排序(字典序)
- 环形字符串最小字典序
- CF - 665E 字典树
- GYM 100883 E.xortion(字典树)
- C++volatile关键字
- android导入文件包详解
- 【程序人生】:牛人高会军
- ubuntu14.04 jdk1.7.0_79 hadoop-2.6.4 完全分布
- BZOJ 1208, 宠物收养所
- CF Gym 字符串字典序
- rosmaster threadpool.py 多线程对同一任务任务队列处理
- September English
- LAMP环境配置
- 华为29
- Memcache监控问题
- 深刻理解Python中的元类(metaclass)
- POJ_3169_Layout
- Ubuntu(Debian)的aptitude与apt-get的基本用法