URAL 1780 G - Gray Code 找规律
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
- Create a 2-bit list: {0, 1}.
- Reflect this list and concatenate it with the original list: {0, 1, 1, 0}.
- Prefix old entries with 0, and prefix new entries with 1: {00, 01, 11, 10}.
- 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}.
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 找规律的更多相关文章
- BZOJ 1228 E&;G(sg函数+找规律)
把一对石子堆看出一个子游戏.打出子游戏的sg表找规律.. 这个规律我是一定找不出来的... 对于i,j,如果 (i-1)%pow(2,k+1) < pow(2,k) (j-1)%pow(2,k+ ...
- 牛客小白月赛 G 异或 找规律
链接:https://www.nowcoder.com/acm/contest/135/G来源:牛客网 题目描述 从前,Apojacsleam家的水族箱里,养了一群热带鱼. 在这几条热带鱼里,Apoj ...
- POJ 1850	 Code(找规律)
Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7913 Accepted: 3709 Description ...
- 2018南京区域赛G题 Pyramid——找规律&;&;递推
先手动推出前10项,再上BM板子求出递推式 $A_n = 5A_{n-1} - 10A_{n-2} + 10A_{n-3} - 5A_{n-4} + A_{n-5}$,根据特征根理论可求出特征方程 $ ...
- Ural 1780 Gray Code 乱搞暴力
原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1780 1780. Gray Code Time limit: 0.5 secondMem ...
- 牛客小白月赛5 G 异或(xor) 【找规律】
题目链接: https://www.nowcoder.com/acm/contest/135/g 题目描述 从前,Apojacsleam家的水族箱里,养了一群热带鱼. 在这几条热带鱼里,Apojacs ...
- ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies (打表找规律+快速幂)
题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直 ...
- Ural 2045. Richness of words 打表找规律
2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...
- Ural 2037. Richness of binary words 打表找规律 构造
2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...
随机推荐
- CLR via C#(18)——Enum
1. Enum定义 枚举类型是经常用的一种“名称/值”的形式,例如: public enum FeedbackStatus { New, Processing, ...
- P1236 算24点
#include <bits/stdc++.h> using namespace std; int b[4]; int a[3]; int calc(int a, int b, int c ...
- keepalive实现web服务器active/passive
https://github.com/acassen/keepalived/blob/v1.2.13/doc/keepalived.conf.SYNOPSIS http://ngyuki.hatena ...
- iOS 开发常用的一些工具
http://www.itjhwd.com/ios-tool/ 通用工具 HomeBrew:OS X上非常出色的包管理工具. 源码控制 Git:分布式版本控制系统和源码管理系统,其优点是:快和简单易用 ...
- NOT 运算符
NOT运算符不是独立的,它是一个可以放在任何逻辑表达式前面的修饰符,能得到与结果相反的结果.所以,如果一个表达式是真,就会得到假:如果是假,就会得到真.有时测试查找条件的反面更容易.不过,NOT运算符 ...
- C#判断文件是否正在被使用
生成文件的时候,如果该文件夹下的同名文件被打开(或者被使用),如果这时再生成一个同名文件,则会提示文件正在被占用. 解决方法有两个,一个是保存的文件名改成该文件夹下不存在的(随机数之类的XXOO都行, ...
- stm32 HAL库笔记(一)——串口的操作
昨天分析了普通io口的使用,和初始化代码流程,回顾一下,首先定义一个配置io口功能的结构体,然后开启时钟,再去配置这个结构体里面的各个成员变量,每个成员变量都有很多种选择,可以看各个成员变量 后面的注 ...
- html form禁止表单回车自动提交(通常原因是为在ajax提交前、后进行js判断控制)
@*onkeydown事件用于禁止回车自动提交form,这样就不经过js控制跳转*@ <form action="/Account/CheckPsw" method=&quo ...
- 想高效学会Hadoop,你要按照这个路线
学习hadoop,首先我们要知道hadoop是什么? 说到底Hadoop只是一项分布式系统的工具,我们在学习的时候要理解分布式系统设计中的原则以及方法,只有这样才能以不变应万变.再一个就是一定要动手, ...
- selenium下firefox自动下载配置及问题
在做自动化测试时,需要从网页上下载相关的文件到指定的目录,一直未能实现 网上正好有个blog文章介绍了如何下载 直接上代码: from selenium import webdriver import ...