B - Equidistant String
B - Equidistant String
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:
We will define the distance between two strings s and t of the same length consisting of digits zero and one as the number of positions i, such that si isn't equal to ti.
As besides everything else Susie loves symmetry, she wants to find for two strings s and t of length n such string p of length n, that the distance from p to s was equal to the distance from p to t.
It's time for Susie to go to bed, help her find such string p or state that it is impossible.
Input
The first line contains string s of length n.
The second line contains string t of length n.
The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.
Output
Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes).
If there are multiple possible answers, print any of them.
Sample Input
Input0001
1011Output0011Input000
111OutputimpossibleHint
In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.
题意:
给定两条长度相等的字符串s和t,字符串之间的距离为两串相同位置不相等元素的个数,问能否得到一个长度与两串相同的字符串p使得p的距离离s,t相等,若有遍输出p。
水啊!s和t的距离ans为偶数就可以,否则就没有。输出的话只要将s的前ans/2个不同的元素转换为与t相同即可得字符串p。
附AC代码:
#include<iostream>
#include<cstring>
using namespace std; string s,t,p; int main(){
cin>>s;
cin>>t;
int ans=;
p=s;
int len=s.size();
for(int i=;i<len;i++){
if(s[i]!=t[i]){
ans++;
t[i]=' ';
}
}
int temp=ans/;
if(ans%==){
for(int i=;i<len;i++){
if(t[i]==' '&&temp){
if(p[i]=='')
p[i]='';
else
p[i]='';
temp--;
}
}
for(int i=;i<len;i++){
cout<<p[i];
}
}
else{
cout<<"impossible";
}
return ;
}
B - Equidistant String的更多相关文章
- Codeforces Round #303 (Div. 2) B. Equidistant String 水题
B. Equidistant String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/54 ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- 周赛-Equidistant String 分类: 比赛 2015-08-08 15:44 6人阅读 评论(0) 收藏
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 545B. Equidistant String
题目链接 输入两个只含有01的字符串,s,t 求一个字符串p使到s,t的距离一样 这里的距离是指对应位置:0-0的距离是0 ,o-1的距离是1 ,1-1的距离是0,1-0的距离是1 这里只要求找出满足 ...
- Codeforces Round #303 (Div. 2) B 水 贪心
B. Equidistant String time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #303 (Div. 2)
A.Toy Cars 题意:给出n辆玩具车两两碰撞的结果,找出没有翻车过的玩具车. 思路:简单题.遍历即可. #include<iostream> #include<cstdio&g ...
- Educational Codeforces Round 121 (Rated for Div. 2)——A - Equidistant Letters
A - Equidistant Letters 题源:https://codeforces.com/contest/1626/problem/A 今天上午VP了这场CF,很遗憾的是一道题也没写出来,原 ...
- 透过WinDBG的视角看String
摘要 : 最近在博客园里面看到有人在讨论 C# String的一些特性. 大部分情况下是从CODING的角度来讨论String. 本人觉得非常好奇, 在运行时态, String是如何与这些特性联系上的 ...
- JavaScript String对象
本编主要介绍String 字符串对象. 目录 1. 介绍:阐述 String 对象的说明以及定义方式. 2. 实例属性:介绍 String 对象的实例属性: length. 3. 实例方法:介绍 St ...
随机推荐
- pycharm5.0 激活方式
Pycharm5注册方式 0x1 ,安装 0x2 , 调整时间到2038年. 0x3 ,申请30天试用 0x4, 退出pycharm 0x5, 时间调整回来. ##注册方法2### 注册方法: ...
- 笔记03 MVVM 开发的几种模式(WPF)
转自http://www.cnblogs.com/buptzym/p/3220910.html 在WPF系(包括SL,WP或者Win8)应用开发中,MVVM是个老生常谈的问题.初学者可能不会有感觉,但 ...
- Java与设计模式-责任链模式
责任链模式属于行为型设计模式之中的一个,怎么理解责任链?责任链是能够理解成数个对象首尾连接而成,每个节点就是一个对象.每个对象相应不同的处理逻辑,直至有一个对象响应处理请求结束.这一种模式成为责任链模 ...
- H5 手机横竖屏判读
$.fn.screenCheck = function() { var pDiv = $('<div></div>'); pDiv.addClass("screenC ...
- 在fedora25x86下编译opencv的Android版本的过程记录
准备材料: 1. 32位的Fedora25(不建议使用64位系统----64位系统下也是可以编译的,这里为了简单起见,考虑使用32位操作系统.事实上,本人在64位操作系统下也做了尝试,也完成了编译.) ...
- java 定义一个同步map内存去重法
实例:
- erlang防止反编译
前面提到了erlang的反编译,下面说下防止反编译: 1)建立~/.erlang.crypt 在编译的用户名的home目录中建立一个加密方法的文件.erlang.crypt,内容如下: [{debug ...
- CSS常识
1.给一个div设置边框:border:1px #CCCCCC bold; 2.给DOM加小手:cursor:pointer; 取消小手:cursor:auto;
- 九度OJ 1125:大整数的因子 (大数运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:974 解决:494 题目描述: 已知正整数k满足2<=k<=9,现给出长度最大为30位的十进制非负整数c,求所有能整除c的k. ...
- mybatis入门小结(六)
入门小结---查询 1.1.1.1.1 #{}和${} #{}表示一个占位符号,通过#{}可以实现preparedStatement向占位符中设置值,自动进行java类型和jdbc类型转换,#{}可以 ...