Codeforces Round #324 (Div. 2)C. Marina and Vasya
A的万般无奈。。。后来跑了大牛的这份代码发现,
题意是求一个序列与给定的两个序列有t个不同。
只要保证。。。对应位置就行了。。
所以处理起来非常方便。。。。。。。。。。。。。。
可是没有感觉是对应位置啊瞎几把想了一堆。后来真的是。
再后来?
我觉得非常好的就是又多了那么点见识。。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const double eps=1e-5;
const double pi=acos(-1.0);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const int N=1e5+7;
bool status[N];
char Generate(char a,char b)
{
char tmp;
for(int i=0;i<26;i++)
{
tmp='a'+i;
if(tmp!=a&&tmp!=b){
return tmp;
}
}
}
int cout_dif(string a,string b,int len)
{
int res=0;
for(int i=0;i<len;i++){
if(a[i]!=b[i])
res++;
}
return res;
}
int main()
{
int n,t,dif=0;
string a,b,c;
cin>>n>>t;
cin>>a>>b;
c=string(n,'a');
vector<int>pos;
memset(status,0,sizeof(status));
for(int i=0;i<n;i++){
if(a[i]!=b[i]) // 统计给定两串的不同字符数为x。【这样特么就能统计???】
dif++;
else
status[i]=1; //标记共同的
}
if(t==dif){
for(int i=0;i<n;i++){
if(status[i]){ //如果是共同的取好
c[i]=a[i];
}
else //不同直接取个更加不同的
c[i]=Generate(a[i],b[i]);
}
}
else if(t>dif){
int cnt=0; //作为标记掉,用来考虑相同里面的t-dif那部分。
for(int i=0;i<n;i++)
{
if(status[i]){
if(cnt<(t-dif))
{
c[i]=Generate(a[i],b[i]);
cnt++;
}
else
c[i]=a[i];
}
else{ //还是要把不同个取个更加不同的
c[i]=Generate(a[i],b[i]);
}
}
}
else //保持相同部分不变,另挑(x-t)个原不同位置,使之与a串相同//同理,b串。
{
int cnt1=0,cnt2=0;
for(int i=0;i<n;i++){
if(status[i])
c[i]=a[i];
else{
if(cnt1<(dif-t)){
c[i]=a[i];
cnt1++;
}
else if(cnt2<(dif-t)){
c[i]=b[i];
cnt2++;
}
else
c[i]=Generate(a[i],b[i]);
}
}
}
if(cout_dif(a,c,n)==t&&cout_dif(b,c,n)==t)
cout<<c<<endl;
else
cout<<"-1"<<endl;
return 0;
}
Codeforces Round #324 (Div. 2)C. Marina and Vasya的更多相关文章
- Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心
C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...
- Codeforces Round #324 (Div. 2)C. Marina and Vasya set
C. Marina and Vasya Marina loves strings of ...
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #324 (Div. 2)
CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...
- Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理
原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心
E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂
B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...
随机推荐
- [ACM] POJ 3253 Fence Repair (Huffman树思想,优先队列)
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25274 Accepted: 8131 Des ...
- 手机号码归属地查询免费api接口代码
依据手机号码查询用户的卡类型.运营商.归属地.区域等信息. 手机归属地实体类 package org.wx.xhelper.model; /** * 手机归属地 * @author wangxw * ...
- 读写锁(pthread)
读写锁: 用于对于某个给定资源的共享访问,而不是像互斥锁那样,将所有试图进入临界区的线程都阻塞住 相关内容: 线程互斥锁 分配规则:(写独占,读共享) 1.只要没有线程持有某个给定的读写锁用于写,那么 ...
- for in 与for of
最近在项目中需要用到遍历对象,用ES6 for of对象后报如下错误 TypeError: [object Object] is not iterable!,网上查询阮大神的教程发现“ES6 的有些 ...
- WPF DataGrid 获取选中 一行 或者 多行
WPF中DataGrid使用时,需要将其SelectedItem转换成DataRowView进行操作 然而SelectedItem 与SelectedItems DataGrid的SelectionU ...
- linux学习:进程间通信—管道
1.进程间通信当中一种比較简单的方法是管道操作 /* ========================================================================= ...
- TiDB 是否支持其他存储引擎?
https://www.pingcap.com/docs-cn/FAQ/ 1.1.11 TiDB 是否支持其他存储引擎? 是的,除了 TiKV 之外,TiDB 还支持一些流行的单机存储引擎,比如 Go ...
- SVN地址正确,能在网页打开,但是检出失败解决方法
TortoiseSVN缓存问题 右键点击TortoiseSVN -> Settings -> Saved Data, 点击个个“Clear”按钮,把本地缓存都清除了,点击“确定”: 再重新 ...
- 自制简单的range(Vue)
废话不多说先上成果图 实现思路 主要分界面与逻辑两大块 界面分为5个部分 左滑块长度 左内容位置 中间长度 右滑块长度 右内容位置 逻辑 touch3个事件 各滑块长度及位置计算 选中时变色 具体实现 ...
- GPS格式标准
GPS接收机串行通信标准摘要 参考NMEA-0183 美国国家海洋电子协会(NMEA—The NationalMarine Electronics Association) 为了在不同的GPS导航设备 ...