Codeforces Round #303 (Div. 2) B 水 贪心
1 second
256 megabytes
standard input
standard output
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.
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.
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.
0001
1011
0011
000
111
impossible
In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.
题意:给你两个长度相同的01串s,t 找到一个新的01串p
使得p与s对应位置 字符不同的数量 等于 p与t对应位置 字符不同 的数量
不存在则输出impossible
题解:遍历一遍统计s,t对应位置字符不同的数量jishu 并标记位置
如果jishu是奇数 则输出impossible 否则 取s串 对于标记的位置 取反jishu/2个位置的值
输出
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#include<cmath>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
char a[];
char b[];
int mp[];
int main()
{
memset(mp,,sizeof(mp));
scanf("%s",a);
scanf("%s",b);
int len=strlen(a);
int jishu=;
for(int i=;i<len;i++)
{
if(a[i]!=b[i])
{ jishu++;
mp[i]=;
}
}
if(jishu%)
{
printf("impossible\n");
return ;
}
jishu/=;
for(int i=;i<len;i++)
{
if(jishu)
{
if(mp[i])
{
if(a[i]=='')
printf("");
else
printf("");
jishu--;
}
else
printf("%c",a[i]);
}
else
printf("%c",a[i]);
}
return ;
}
Codeforces Round #303 (Div. 2) B 水 贪心的更多相关文章
- Codeforces Round #303 (Div. 2) C. Woodcutters 贪心
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- Codeforces Round #303 (Div. 2) D. Queue —— 贪心
题目链接:http://codeforces.com/problemset/problem/545/D 题解: 问经过调整,最多能使多少个人满意. 首先是排序,然后策略是:如果这个人对等待时间满意,则 ...
- Codeforces Round #303 (Div. 2) C dp 贪心
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #303 (Div. 2) A 水
A. Toy Cars time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 水题 Codeforces Round #303 (Div. 2) D. Queue
题目传送门 /* 比C还水... */ #include <cstdio> #include <algorithm> #include <cstring> #inc ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- 水题 Codeforces Round #303 (Div. 2) A. Toy Cars
题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...
- DP Codeforces Round #303 (Div. 2) C. Woodcutters
题目传送门 /* 题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒 问最多能砍到多少棵树 DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树 分情况讨论,若符合就取最 ...
- Codeforces Round #303 (Div. 2) D. Queue 水题贪心
题目: 题意:给你n个数值,要求排列这个序列使得第k个数值的前K-1个数的和>=第k个数值的个数尽可能多: #include <iostream> #include <cstd ...
随机推荐
- BroadCastReceiver相关知识--读书笔记
2013-12-30 16:55:07 1. BroadCastReceiver是Android四大组件之一,本质上是一个系统级的监视器. 2. 每次BroadCast事件发生后,系统都会创建对应的B ...
- struts2 通用标签
*property 标签 property 标签用来输出一个值栈属性的值, 对于对象栈,打印值栈中对应的属性值:对于Map 栈,打印request,session,application的某个属性值或 ...
- centos7 学习1 KDE配置中文
安装kde桌面后没有中文,可以用以下方法配置中文 #yum list kde*chinese 会显示可以安装的包,我的显示如下 kde-l10n-Chinese.noarch -.fc14 @upda ...
- getBoundingClientRect() 来获取页面元素的位置
getBoundingClientRect() 来获取页面元素的位置 document.documentElement.getBoundingClientRect 下面这是MSDN的解释: Syn ...
- 中国广核集团:BPM与ERP紧密结合
全球能源消耗不断增长,电能已经达到了无可替代的位置.同时,传统的电力供应模式正在受新模式的影响,营造更具价值的生态系统.面对挑战,核电企业在提高能效并降低成本的同时,也迫切需要进行转型.面对公众对可再 ...
- web安全测试-AppScan
安全测试应该是测试中非常重要的一部分,但他常常最容易被忽视掉. 尽管国内经常出现各种安全事件,但没有真正的引起人们的注意.不管是开发还是测试都不太关注产品的安全.当然,这也不能怪我们苦B的“民工兄弟” ...
- angularJs 自定义服务 provide 与 factory 的区别
<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...
- 嵌入dll到rtf文件
嵌入文件到doc文件中, 打开word--->插入菜单---->对象--->新建---->对象类型----->Package---->弹出创建软件包界面-----& ...
- TCP同步传送数据示例(简洁、清楚)
转自:http://www.2cto.com/kf/201206/134841.html 本例子写了个简单的TCP数据传送功能.没有使用BinaryWriter,BinaryReader,而是使用Ne ...
- Ubuntu 14.10 下安装中文输入法
系统默认带的是IBUS,这个不怎么好用,我们需要安装一个新的框架FCITX 1 打开软件中心,输入fcitx,安装flexible input method framework 2 下载需要的输入法, ...