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 ...
随机推荐
- viewState详解
作者:Infinities Loop 概述 ViewState是一个被误解很深的动物了.我希望通过此文章来澄清人们对 ViewState的一些错误认识.为了达到这个目的,我决定从头到尾详细的描述一下整 ...
- 最新研发的基于Java的高速开发平台
可自我扩展的智能开发平台 在开发平台设计过程中,联科研发部一開始就希望能研发一套智能开发机制能自己开发自己的平台-即一个能自我修复和自我扩展的开发平台.这个开发平台不但能开发其它应用还能不 ...
- Vue 资源
一. 资源教程 综合类 vuejs 英文资料 Vue中文资料总汇 Vue.js 的一些资源索引 vue资料 入门类 vue 快速入门 Vue.js 中文系列视频教程 on Laravist 英文教程 ...
- js实现网页端复制功能
实现网页端复制功能: <div id="copyInput" style="display:none;"> <form> <inp ...
- 关于arr.map()问题
最近看map实现原理, Array.prototype._map = function(fn, context) { console.log(fn, context) var temp = []; i ...
- java 最长回文字串
package string.string1_6; public class LongestPalidrome { /** * 使用常规方法, 以字符串的每一个字符作为中心进行判断, 包括奇数和偶 ...
- dwr框架中DWRUtil的方法
dwr框架中DWRUtil的方法 2008-10-14 17:57:23| 分类: JAVA | 标签: |举报 |字号大中小 订阅 7. util.js 功能 util.js包含了一些工 ...
- Server.xml配置详解
<Server port="8005" shutdown="SHUTDOWN"> <!-- 属性说明 port:指定一个端口,这个端口负责监听 ...
- Linux把查询结果写入到文本
在Linux命令模式下,可以将查询结果写入文件.大概有两种方式,增量写入和覆盖写入. 增量写入: #iostat -m >> /tmp/iostat.txt 覆盖写入: #iostat - ...
- The basic principle of test case 修改引擎
The basic principle of test case evaluation is that output resulting from running a test case is com ...