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 ...
随机推荐
- Oracle 课程八之跟踪事件set event
一.Oracle跟踪文件 Oracle跟踪文件分为三种类型: 一种是后台报警日志文件,记录数据库在启动.关闭和运行期间后台进程的活动情况,如表空间创建.回滚段创建.某些alter命令.日志切换.错误消 ...
- Matlab编程实例(4) 相位角与相关系数曲线
%相位角与相关系数曲线 close all; clear all; Samp1=200; %设置信号的采样精度 Samp2=200; %设置相位角p分割精度 A=10;%信号幅值 w=1;%信号角 ...
- 《Python CookBook2》 第四章 Python技巧 - 若列表中某元素存在则返回之 && 在无须共享引用的条件下创建列表的列表
若列表中某元素存在则返回之 任务: 你有一个列表L,还有一个索引号i,若i是有效索引时,返回L[i],若不是,则返回默认值v 解决方案: 列表支持双向索引,所以i可以为负数 >>> ...
- 高精度+搜索+质数 BZOJ1225 [HNOI2001] 求正整数
// 高精度+搜索+质数 BZOJ1225 [HNOI2001] 求正整数 // 思路: // http://blog.csdn.net/huzecong/article/details/847868 ...
- 定位程序问题的方法 -- clwu
原本的标题的<定位程序代码的方法>,但问题有时候超出了自己代码的范围,而是别人的程序,所以今天想分享的是一个通用的分析问题(程序)的思路. 先来说一下在使用别人的程序(Vim)过程中遇到问 ...
- [置顶] Kendo UI开发教程: Kendo UI 示例及总结
前面基本介绍完Kendo UI开发的基本概念和开发步骤,Kendo UI的示例网站为http://demos.kendoui.com/ ,包含了三个部分 Web DemoMobile DemoData ...
- Spark的应用程序
Spark的应用程序,分为两部分:Spark driver 和 Spark executor.
- CalendarUtil
package ch.makery.address.util; import java.text.ParseException; import java.text.SimpleDateFormat; ...
- keil中编译时出现*** ERROR L107: ADDRESS SPACE OVERFLOW
解决方法: http://zhidao.baidu.com/link?url=DWTVVdALVqPtUt0sWPURD6c1eEppyu9CXocLTeRZlZlhwHOA1P1xdesqmUQNw ...
- Chrome的Postman的使用
Chrome提供了一个很好的Web App 名为 Postman 使用这个web app,你可以输入一个url,然后可以很清楚的看到返回的各种结果 直接在Google中输入Postman, 找到它 ...