Codeforces 584C Marina and Vasya
来源:互联网 发布:js调用点击事件 编辑:程序博客网 时间:2024/06/07 13:25
原题见CF 584C
给1~
范围并不大,可以当作模拟题啊。
先统计字符相同的子串s,长为slen,将其存在一个结构体里。剩下的是不同的子串d1,d2,长为dlen。
可以得到t的范围在
如图,颜色相同的地方表示字符相同。于是可以照着如图的拼法得到相应的元素,并将其对应到原位置。
当时错在了产生一个和两个字符均不同的字符,用了较大者加一。反例即(a,z)->a.哎,好惨~~
附code:
/*-------------------------------------------- * File Name: CF 584 C * Author: Danliwoo * Mail: Danliwoo@outlook.com * Created Time: 2015-10-07 01:11:20--------------------------------------------*/#include <cstdio>#include <iostream>#include <cstring>#include <queue>#include <algorithm>#include <cmath>using namespace std;#define N 1000010struct node{ int x; char y; node(){} node(int a, char b){ x = a, y = b; }}d[2][N], s[N];char str1[N], str0[N], ans[N];int dlen, slen;char get(char x, char y){ if(x != 'a' && y != 'a') return 'a'; if(x != 'b' && y != 'b') return 'b'; if(x != 'c' && y != 'c') return 'c';}int main(){ int n, t; while(~scanf("%d%d", &n, &t)) { scanf("%s%s", str0, str1); dlen = slen = 0; for(int i = 0;i < n;i++) { if(str0[i] == str1[i]) s[slen++] = node(i, str1[i]); else { d[0][dlen] = node(i, str0[i]); d[1][dlen++] = node(i, str1[i]); } } if(t < (dlen+1)/2 || t > n) { printf("-1\n"); continue; } int q = min(t, dlen); for(int i = 0;i < q;i++) ans[d[0][i].x] = d[0][i].y; for(int i = q;i < dlen-q;i++) ans[d[1][i].x] = d[1][i].y; for(int i = dlen-q;i < dlen;i++) ans[d[0][i].x] = get(d[0][i].y, d[1][i].y); int p = max(t-dlen, 0); for(int i = 0;i < p;i++) ans[s[i].x] = (s[i].y-'a'+1)%26+'a'; for(int i = p;i < slen;i++) ans[s[i].x] = s[i].y; ans[n] = '\0'; printf("%s\n", ans); } return 0;}
0 0
- Codeforces 584C Marina and Vasya
- codeforces 584C Marina and Vasya
- Codeforces 584C Marina and Vasya 【构造】
- Codeforces 584C Marina and Vasya
- CodeForces 584C - Marina and Vasya(构造)
- codeforces 584C Marina and Vasya
- Codeforces Round #324 (Div. 2) 584C. Marina and Vasya
- CodeForces - 584C Marina and Vasya (模拟)找规律
- Codeforces 584 C Marina and Vasya【构造+贪心】
- Codeforces Round #324 C Marina and Vasya
- codeforces 324# C. Marina and Vasya (贪心)
- Codeforces 584 C. Marina and Vasya (Codeforces Round #324 (Div. 2))
- Codeforces Round #324 (Div. 2)C. Marina and Vasya
- Codeforces Round #324 (Div. 2) C. Marina and Vasya
- Codeforces #324 Div2 C Marina and Vasya(构造)
- Codeforces Round #324 (Div. 2)C. Marina and Vasya
- 【打CF,学算法——二星级】Codeforces 584C Marina and Vasya (简单构造)
- Code Forces 584 C. Marina and Vasya(水~)
- VS2013 MFC右键弹出菜单
- xcode7 中到导入ReactiveCocoa框件创建过程 和 解决 Box.swift出错、MutableBox.swift出错
- c#,使用WMI对象获取笔记本电池剩余电量的百分比
- centos 7 安装LAMP+PHPMYADMIN
- C语言合法标识符
- Codeforces 584C Marina and Vasya
- 软件测试理论
- JSP基础
- 银联基于OpenStack的金融私有云建设实践
- 作业2
- iOS项目更新之升级Xcode7 & iOS9
- 最老程序员创业开发实训4---IOS平台下MVC架构
- 【特种兵PPT教程】如何把你的PPT转换成视频?
- IT技术面常问面试问题