G - Gray Code
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87643#problem/G

Description

Denis, Vanya and Fedya gathered at their first team training. Fedya told them that he knew the algorithm for constructing a Gray code.
  1. Create a 2-bit list: {0, 1}.
  2. Reflect this list and concatenate it with the original list: {0, 1, 1, 0}.
  3. Prefix old entries with 0, and prefix new entries with 1: {00, 01, 11, 10}.
  4. Repeat steps 2 and 3 until the length of all elements is equal to n.

The number n is a length of a Gray code. For example, the code of length 3 is: {000, 001, 011, 010, 110, 111, 101, 100}.

Denis ran the Fedya's algorithm and obtained a binary number x at position k (positions are numbered starting from zero). Vanya wrote down the numbers k and x in binary system. This story happened many years ago and now you hold the paper sheet with these numbers in your hands. Unfortunately, some digits are unreadable now. Could you determine the values of these digits using the readable digits?

Input

The first line contains a number k written in the binary system. Unreadable digits are denoted with symbol “?”. The second line contains a number x in the same format. The lengths of these numbers are equal and don't exceed 10 5. The numbers may contain leading zeroes.

Output

If there is a unique way to restore the numbers k and x, output them, replacing the symbols “?” with “0” or “1”. If there are multiple ways to restore them, output “Ambiguity”. If Denis or Vanya certainly made a mistake in these numbers, output “Impossible”.

Sample Input

0?1
0?0

Sample Output

011
010

HINT

题意

题目给了一种序列的构造方式

然后给你一个k,判断第k个数是不是说给的x

题解

找规律题,注意翻转= =

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
#include <bitset>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) const char * fail = "Impossible";
const char * more = "Ambiguity";
using namespace std;
const int maxn = 1e5 + ;
int dp[maxn][];
char s1[maxn] , s2[maxn]; int main(int argc,char *argv[])
{
scanf("%s%s",s1+,s2+);
int Length = strlen(s1+);
s1[] = '';
for(int i = Length ; i > ; -- i)
{
if (s2[i] == '')
{
//同号
if (s1[i] == '' && s1[i-] == '') continue;
if (s1[i] == '' && s1[i-] == '')
{
printf("%s\n",fail);
return ;
}
if(s1[i] == '' && s1[i-] == '?')
{
s1[i-] = '';
continue;
}
if (s1[i] == '' && s1[i-] == '')
{
printf("%s\n",fail);
return ;
}
if (s1[i] == '' && s1[i-] == '') continue;
if (s1[i] == '' && s1[i-] == '?')
{
s1[i-] = '';
continue;
}
if (s1[i] == '?' && s1[i-] == '')
{
s1[i] = '';
continue;
}
if (s1[i] == '?' && s1[i-] == '')
{
s1[i] = '';
continue;
}
if (s1[i] == '?' && s1[i-] == '?') continue;
}
if (s2[i] == '')
{
//异号
if (s1[i] == '' && s1[i-] == '') continue;
if (s1[i] == '' && s1[i-] == '')
{
printf("%s\n",fail);
return ;
}
if(s1[i] == '' && s1[i-] == '?')
{
s1[i-] = '';
continue;
}
if (s1[i] == '' && s1[i-] == '') continue;
if (s1[i] == '' && s1[i-] == '')
{
printf("%s\n",fail);
return ;
}
if(s1[i] == '' && s1[i-] == '?')
{
s1[i-] = '';
continue;
}
if(s1[i] == '?' && s1[i-] == '')
{
s1[i] = '';
continue;
}
if(s1[i] == '?' && s1[i-] == '')
{
s1[i] = '';
continue;
}
if(s1[i] == '?' && s1[i-] == '?') continue;
}
}
for(int i=;i<=Length;i++)
if(s1[i]=='?')
{
if(s2[i]!='?')
{
if(s2[i]=='') s1[i]=s1[i-];else s1[i]=''+-(s1[i-]-'');
continue;
}
printf("%s\n",more);
return ;
}
for(int i=;i<Length;i++)
if(s1[i]!=s1[i+])
{
s2[i+]='';
}
else s2[i+]='';
printf("%s\n%s\n",s1+,s2+);
return ;
}

URAL 1780 G - Gray Code 找规律的更多相关文章

  1. BZOJ 1228 E&G(sg函数+找规律)

    把一对石子堆看出一个子游戏.打出子游戏的sg表找规律.. 这个规律我是一定找不出来的... 对于i,j,如果 (i-1)%pow(2,k+1) < pow(2,k) (j-1)%pow(2,k+ ...

  2. 牛客小白月赛 G 异或 找规律

    链接:https://www.nowcoder.com/acm/contest/135/G来源:牛客网 题目描述 从前,Apojacsleam家的水族箱里,养了一群热带鱼. 在这几条热带鱼里,Apoj ...

  3. POJ 1850 Code(找规律)

    Code Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7913   Accepted: 3709 Description ...

  4. 2018南京区域赛G题 Pyramid——找规律&&递推

    先手动推出前10项,再上BM板子求出递推式 $A_n = 5A_{n-1} - 10A_{n-2} + 10A_{n-3} - 5A_{n-4} + A_{n-5}$,根据特征根理论可求出特征方程 $ ...

  5. Ural 1780 Gray Code 乱搞暴力

    原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1780 1780. Gray Code Time limit: 0.5 secondMem ...

  6. 牛客小白月赛5 G 异或(xor) 【找规律】

    题目链接: https://www.nowcoder.com/acm/contest/135/g 题目描述 从前,Apojacsleam家的水族箱里,养了一群热带鱼. 在这几条热带鱼里,Apojacs ...

  7. ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies (打表找规律+快速幂)

    题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直 ...

  8. Ural 2045. Richness of words 打表找规律

    2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...

  9. Ural 2037. Richness of binary words 打表找规律 构造

    2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...

随机推荐

  1. mysql大内存高性能优化方案

    mysql优化是一个相对来说比较重要的事情了,特别像对mysql读写比较多的网站就显得非常重要了,下面我们来介绍mysql大内存高性能优化方案 8G内存下MySQL的优化 按照下面的设置试试看:key ...

  2. [转] AE中如何由IFeature 如何获取所对应的FeatureClass

    转载的原文 AE中如何由IFeature 如何获取所对应的FeatureClass   先获取FeatureClass,然后遍历Map中所有的FeatureLayer,然后比较 FeatureClas ...

  3. Android:实现一种浮动选择菜单的效果

    总结如何实现Android浮动层,主要是dialog的使用. 自定义一个类继承自Dialog类,然后在构造方法中,定义这个dialog的布局和一些初始化信息. 案例1: public class Me ...

  4. IIS配置网站(WebServices),局域网都能访问

    IIS配置网站(WebServices),局域网都能访问 前言 上篇说到在本机创建一个WebServices,用控制台应用程序调用WebServices的SayHello方法. http://www. ...

  5. 20、内存溢出(Out of Memory)

     内存引用(释放强引用) Object obj=new Object(); obj = null;  内存引用(使用软引用) 软引用是主要用于内存敏感的高速缓存.在jvm报告内存不足之前会清 除所 ...

  6. .net获取当前网址url(各种参数值)

    .net获取当前网址url(各种参数值) 假设当前页完整地址是:http://www.test.com/aaa/bbb.aspx?id=1&name=category" 先来看一下整 ...

  7. 详谈C++保护成员和保护继承

    protected 与 public 和 private 一样是用来声明成员的访问权限的.由protected声明的成员称为“受保护的成员”,或简称“保护成员”.从类的用户角度来看,保护成员等价于私有 ...

  8. Java每日一则-002

    Java中包的层级关系 java中的包在逻辑上是没有套嵌的,也就是说: java.lang 和 java.lang.awt 是两个平行的包,地位相等,互不相关.只不过一个名字叫java.lang另一个 ...

  9. mapreduce的调度算法和job调优

    调度算法: mapreduce当有很多的作业在执行的时候,是按照什么顺序去执行的? 调度算法顺序需要关注: 1.提高作业的吞吐量. 2.要考虑优先级. 三种调度器:如果作业跑不完,并且机器资源利用率比 ...

  10. Python字典方法copy()和deepcopy()的区别

    from copy import deepcopy # import deepcopy模块 d = {} d['name'] = ['black', 'guts'] # d = {'name': [' ...