Codeforces Round #155 (Div. 2)
来源:互联网 发布:查看网络路由节点 编辑:程序博客网 时间:2024/06/07 01:36
A:找出数列中两个相同的数字,并输出原数组的下标;思路就是用个结构体储存数值和原数组下标,接着排序后输出就行了。
B:这问题可以简化为求哪个点的的值最大,比赛时没想到。。比赛后看别人的代码才恍然大悟。。不过我觉得自己的方法也没什么错啊,但就是不对TAT。。
C:这题不错啊,赛后A的,就是给出两个串s,t,求s最少经过多少次字母变换,使得s中每个字母的数目和t的一样;做这题的时候,因为实力有限,YY了一天(还好YY出来的思路是对的)。。思路是贪心的,就是线扫每个字符串,若当前字符在s中的数量比t中的少,就看能否替换字典序比当前字符小的字母,若要替换的字典序比当前字母大的就尽量往字符串后面填。。如s:ABA t:ABC,当扫描到第一个A的时候,发现s中A有两个,t中A只有1个,则需替换成C,因为C的字典序比A大,所以尽量在后面替换,所以应将第二个A替换成C,答案是ABC;
这题写的时候,调试的时候对着数据调试,不过这习惯非常不好,因为比赛时是不可以看错在哪组数据的;觉得差不多了。。
就提交。。居然是TLE,以为哪里循环多了。。然后就修改了下,少了些循环,再提交又TLE,连续TLE了几次。。。然后我怀疑不是算法问题了。。而是哪里有点不对,然后翻了翻别人的代码,结果将自己读取字符串长度改了下就A了。。晕死了+_+;
超时的循环,个人认为是每次循环判断结束的条件的时候都会算下字符串的长度(本题的字符串长度为10^5),导致时间大增;
for(i=0;i<strlen(s);i++)
正确的循环,将字符串长度存入一个值中;
int len=strlen(s);for(i=0;i<len;i++)
C:
//author Joy#include<cstdio>#include<cstdlib> #include<cstring>#include<cmath>#include<cctype> #include<algorithm>#include<iostream> #include<queue>#include<stack>#include<map>#include<set>#include<vector> #define arrSize 101000#define strSize 101000#define gridSize 30 using namespace std;typedef struct coor{ int index; char ch;};int nomalDay[]={0,31,28,31,30,31,30,31,31,30,31,30,31};//平年 int leapDay[]={0,31,29,31,30,31,30,31,31,30,31,30,31};//闰年 const int maxinf=(2<<20);const int mininf=(~(2<<20)); inline bool upcmp(int a,int b){return a<b;}inline bool downcmp(int a,int b){ return a>b;}/*---------------分割线---------------*/ char s[strSize],t[strSize];int sn[gridSize],tn[gridSize],cnt[gridSize];int main(){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int i,j,res=0,len; memset(sn,0,sizeof(sn)); memset(tn,0,sizeof(tn)); memset(cnt,0,sizeof(cnt)); cin>>s>>t; len=strlen(s); for(i=0;i<len;i++) { sn[s[i]-'A']++; cnt[s[i]-'A']++; tn[t[i]-'A']++; } for(i=0;i<len;i++) { int ss=sn[s[i]-'A'],tt=tn[s[i]-'A']; int idx=s[i]-'A',f=0; int dis=ss-tt; if(ss<=tt) continue; //若S有字母个数比T少,变成T中对应的字母 if(ss>tt) { cnt[idx]--; for(j=0;j<idx;j++) if(sn[j]<tn[j]) { sn[j]++; sn[idx]--,res++; s[i]='A'+j,f=1; break; } } if(!f&&cnt[idx]<dis) { for(j=0;j<26;j++) if(sn[j]<tn[j]) { sn[j]++; sn[idx]--,res++; s[i]='A'+j; break; } } } cout<<res<<endl<<s; return 0;}
- Codeforces Round #155 (Div. 2)
- Codeforces Round #155 (Div. 2)
- Codeforces Round #155 (Div. 2)
- Codeforces Round #155 (Div. 2)
- Codeforces Round #155 (Div. 2)
- Codeforces Round #155 (Div. 2)
- Codeforces Round #155 (Div. 2) D-rats
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Codeforces Round #121 (Div. 2)
- 【ubuntu Androiid源码起板子配置】
- Eclipse编码设置
- Linux下串口编程
- android中的ImageButton,RadioGroup,CheckBox,ToggleButton
- oracle优化的几个简单步骤
- Codeforces Round #155 (Div. 2)
- Js数组pop,push,unshift,splice,shift方法
- Linux ALSA声卡驱动之八:ASoC架构中的Platform
- IDEA InteliJ 中Make 复制文件到输出目录
- Extjs控件EditorGridPanel中使用自定义的editor
- C语言setjump函数理解
- MIT人工智能实验室:如何做研究
- android数据存储之SQLite(个人日记本)
- mysql操作大全