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 ...
随机推荐
- 提升WordPress站点速度的八个建议
WordPress是一个很棒的开源程序,几乎我认识的站长朋友当中,粗略估算有80%使用Wordpress.但很棒不等于完美,就在我所认识的这些朋友中,几乎所有人都会抱怨Wordpress太臃肿,运行效 ...
- 一个socket发送调试信息的类
using UnityEngine; using System.Collections; using System; using System.Net.Sockets; using System.Ne ...
- Arithmetic Progressions
题目大意: 求出满足条件A的等差数列: A:长度为N(N<=25),每个元素都能表示成 两个数p,q的平方和(0<=p,q<=m<=250): 解题过程: 1.处理出所有的能拆 ...
- 基于MVC的应用框架之Struts前奏
1.JSP&Servlet中的MVC MVC的关键是,业务逻辑要与表示分离.通过把业务逻辑放在一个“模型”中,这样业务逻辑本身就能作为一个可重用的JAVA类存在. 在JSP&Servl ...
- Quartz 2D 图形上下文栈 矩阵 裁剪
Quartz 2D 图形上下文栈 矩阵 // // DJVIew.m // 图形上下文栈 // // Created by zjj on 15/6/30. // Copyright (c) 2015 ...
- JavaScript 数组方法和属性
一. 数组对象的操作方法 1. 数组的创建 2.prototype属性 返回对象原型的引用,prototype属性时object共有的. objectName.prototype,其中objectNa ...
- php操作文件(读取写入文件)
一,PHP如何读取文件 PHP读取文件可以读取当前服务器或远程服务器中的文件.其步骤是:打开文件.读文件和关闭文件. 1,PHP如何打开文件 使用PHP函数fopen()打开一个文件,fopen()一 ...
- 使用plsql连接别人的oracle(转)
文章来源:http://www.linuxidc.com/Linux/2013-04/82738.htm oracle服务有时候我们觉得太大,所以我们只需要在本机上装一个oracle客户端和plsql ...
- Visual Studio环境色调配色
据说对眼睛有好处的色调配色 vs 色调rgb 199,240,214 色调为84,饱和度为91,亮度为205 色调为85,饱和度为123,亮度205: “色调”由160更改为75-85之间——> ...
- 2013年7月底至8月初51Aspx源码发布详情
兼职人员信息管理系统源码 2013-8-2 [VS2008]2013.8.2更新内容:修改了一级菜单不能修改的bug.功能介绍:兼职人员信息管理:添加,修改,删除,查询,支持数据导出Excel,按多 ...