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 ...
随机推荐
- 关于position的小总结
position:relative/absolute/fixed/static ...... relative:相对定位. 脱离标准流,相对自己原来(标准流)的位置定位.absolute:绝对定位. ...
- 线程安全使用(四) [.NET] 简单接入微信公众号开发:实现自动回复 [C#]C#中字符串的操作 自行实现比dotcore/dotnet更方便更高性能的对象二进制序列化 自已动手做高性能消息队列 自行实现高性能MVC WebAPI 面试题随笔 字符串反转
线程安全使用(四) 这是时隔多年第四篇,主要是因为身在东软受内网限制,好多文章就只好发到东软内部网站,懒的发到外面,现在一点点把在东软写的文章给转移出来. 这里主要讲解下CancellationT ...
- Python+Selenium框架设计--- Page Object Model
POM(Page Object Model):页面对象模型,POM是一种最近几年非常流行的自动化测试模型,或者思想,POM不是一个框架,就是一个解决问题的思想.采用POM的目的,是为了解决前端中UI变 ...
- 微博达人硅谷之歌:Testin云測移动搜索性能測试非常是让人信服
微博达人硅谷之歌:Testin云測移动搜索性能測试非常是让人信服 2014/10/08 · Testin · 开发人员訪谈 2013年11月1日,谷歌运行董事长施密特(Eric Emerson Sch ...
- angular 绑定数据时添加HTML标签被识别的问题
由于安全性,angular本身会对绑定的HTML标签属性进行转义,所以有些情况下我们需要用到绑定的数据里面传入html标签的时候, 需要用到一个服务:$sce $sce 服务下面的一个 $sce.tr ...
- windows下gVim 中文显示为乱码
打开vimrc文件,在vim的安装目录下可以找到该文件: 或在windows下是在vim/gvim下输入:edit $vim/_vimrc. 在文件的末尾添加一句 "set fileenco ...
- 数据库中表的复杂查询&分页
一.数据库中表的复杂查询 1)连接查询 1.0连接的基本的语法格式: from TABLE1 join_type TABLE2 [on (join_condition)][where (query_c ...
- linux关机命令详解(转载)
在linux下一些常用的关机/重启命令有shutdown.halt.reboot.及init,它们都可以达到重启系统的目的,但每个命令的内部工作过程是不同的. Linux centos重启命令: 1. ...
- FFMPEG SDK流媒体开发2---分离.mp4等输入流音视频而且进行解码输出
对于FFMPEG SDK 提供的Demuxing 为我们实现多路复用 提供了非常多方便,以下的案案例 实现的是 分离一个媒体文件的音频 视频流 而且解码输出 到 不同的文件里. 对于音频被还原回 ...
- EasyDarwin开源手机直播方案:EasyPusher手机直播推送,EasyDarwin流媒体服务器,EasyPlayer手机播放器
在不断进行EasyDarwin开源流媒体服务器的功能和性能完善的同时,我们也配套实现了目前在安防和移动互联网行业比较火热的移动端手机直播方案,主要就是我们的 EasyPusher直播推送项目 和 Ea ...