HDU 4733 G(x) (2013成都网络赛,递推)
G(x)
Time Limit: 2000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 184 Accepted Submission(s): 44

Where "
" is bitwise XOR operation and "
" indicates the largest integer which is not greater than x.Due to some reasons, Mzry1992 encode his password P into G(P), and additionally, he encode P + 1 into G(P + 1) too, and write G(P) and G(P + 1) into his diary.
This story happened many years ago and now you hold the diary with these numbers in your hands. Unfortunately, some digits are unreadable now. Could you determine the values of these digits using the readable digits?
For every test case, it has 2 lines of same number of digits describe G(P) and G(P + 1), In every line, it only contains 1, 0 and ?. Unreadable digits are denoted with symbol ?, The length of every line in the input is up to 105.
Then, if there is impossible to restore G(P) and G(P + 1), you should output "Impossible" in the second line.
Otherwise, if G(P) is unique, you should output restored G(P) and G(P +1) in the same format.
Otherwise, you should output "Ambiguous" and the number of possible G(P) in the second line.
The number may be very large so the answer should modulo 10^9 + 7.
10??
10??
0010
0110
1?01
0?01
Ambiguous 3
Case #2:
0010
0110
Case #3:
Impossible
In the first sample case, the three possible situations are:
1.
G(12) = 1010
G(13) = 1011
2.
G(13) = 1011
G(14) = 1001
3.
G(14) = 1001
G(15) = 1000
很容易找出规律,
然后递推,枚举就解决了。
P和P+1 其实就是差后面一点
P: XXXXX 0 1 1 1
P+1: XXX 1 0 0 0
关键点就是枚举P的第一个0的位置。左边的P和P+1是一样的。
/* ***********************************************
Author :kuangbin
Created Time :2013/9/14 星期六 14:16:53
File Name :2013成都网络赛\1006.cpp
************************************************ */ #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; const int MAXN = ;
const int MOD = 1e9+;
char str1[MAXN], str2[MAXN];
int dp[MAXN][];
int flag[MAXN][]; char sss1[MAXN],sss2[MAXN]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int iCase = ;
scanf("%d",&T);
while(T--)
{
iCase++;
printf("Case #%d:\n",iCase);
scanf("%s%s",str1,str2);
int n = strlen(str1);
dp[][] = ;
dp[][] = ;
flag[][] = ;
flag[][] = ;
for(int i = ;i <= n;i++)
{
if(str1[i-] == '?' && str2[i-] == '?')
{
dp[i][] = dp[i-][] + dp[i-][];
dp[i][] = dp[i-][] + dp[i-][];
int tmp = flag[i-][] + flag[i-][];
if(tmp == )
flag[i][] = flag[i][] = ;
else if(tmp == )
flag[i][] = flag[i][] = ;
else flag[i][] = flag[i][] = ;
}
else if(str1[i-] == '?' || str2[i-] == '?')
{
if(str1[i-] == '' || str2[i-] =='')
{
dp[i][] = dp[i-][];
dp[i][] = dp[i-][];
flag[i][] = flag[i-][];
flag[i][] = flag[i-][];
}
else if(str1[i-] == '' || str2[i-] =='')
{
dp[i][] = dp[i-][];
dp[i][] = dp[i-][];
flag[i][] = flag[i-][];
flag[i][] = flag[i-][];
}
}
else if(str1[i-] != str2[i-])
{
dp[i][] = dp[i][] = ;
flag[i][] = flag[i][] = ;
}
else
{
if(str1[i-] =='')
{
dp[i][] = dp[i-][];
dp[i][] = dp[i-][];
flag[i][] = flag[i-][];
flag[i][] = flag[i-][]; }
else
{
dp[i][] = dp[i-][];
dp[i][] = dp[i-][];
flag[i][] = flag[i-][];
flag[i][] = flag[i-][];
}
}
if(dp[i][] >= MOD)dp[i][] -= MOD;
if(dp[i][] >= MOD)dp[i][] -= MOD;
}
int ans = ;
int flag_num = ;
int ss_id = -;
for(int i = n;i > ;i--)
{
if(i+ <= n)
{
if(str1[i+] == '' || str2[i+] == '')
break;
}
if(i+ <= n)
{
if(str1[i] == '' || str2[i] == '')
continue;
}
if(i- >= )
{
if(str1[i-] == str2[i-] && str1[i-] != '?')
continue;
}
char ch;
if(str1[i-] == str2[i-] && str1[i-] == '?')
{
ans += dp[i-][];
ans %= MOD;
ans += dp[i-][];
ans %= MOD;
flag_num += flag[i-][] + flag[i-][];
if(flag_num > )flag_num = ;
}
else
{
if(str1[i-] != '?')ch = str1[i-];
else
{
if(str2[i-] == '')ch = '';
else ch = '';
}
if(ch == '')
{
ans += dp[i-][];
ans %= MOD;
flag_num += flag[i-][];
if(flag_num > )flag_num = ;
}
else
{
ans += dp[i-][];
ans %= MOD;
flag_num += flag[i-][];
if(flag_num > )flag_num = ;
}
}
if(flag_num == && ss_id == -)ss_id = i;
}
if(flag_num == )
{
printf("Impossible\n");
continue;
}
if(flag_num > )
{
printf("Ambiguous %d\n",ans);
continue;
}
if(flag_num == )
{
sss1[n] = sss2[n] = ;
sss1[ss_id-] = '';
sss2[ss_id-] = '';
for(int i = ss_id;i < n;i++)
sss1[i] = '', sss2[i] = '';
int last = ;
for(int i = ss_id-;i >= ;i--)
{
int now;
if(flag[i+][] > )now = ;
else now = ;
sss1[i] = sss2[i] = '' + now; }
for(int i = n-; i > ;i--)
{
if(sss1[i-] ==sss1[i])sss1[i] = '';
else sss1[i] = '';
if(sss2[i-] == sss2[i])sss2[i] = '';
else sss2[i] = '';
} printf("%s\n%s\n",sss1,sss2);
continue;
}
cout<<ans<<endl; }
return ;
}
HDU 4733 G(x) (2013成都网络赛,递推)的更多相关文章
- HDU 4730 We Love MOE Girls (2013成都网络赛,签到水题)
We Love MOE Girls Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4737 A Bit Fun (2013成都网络赛)
A Bit Fun Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 4734 F(x) (2013成都网络赛,数位DP)
F(x) Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)
Minimum palindrome Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 4747 Mex (2013杭州网络赛1010题,线段树)
Mex Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4737 A Bit Fun 2013成都 网络赛 1010
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4737 题目大意:给定一系列数,F(i,j)表示对从ai到aj连续求或运算,(i<=j)求F(i, ...
- 2013成都网络赛 C We Love MOE Girls(水题)
We Love MOE Girls Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 2013成都网络赛 J A Bit Fun(水题)
A Bit Fun Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- JD m站自我解析理解
第一步:从首页着手 文档部分:应用的是H5默认文档开头 即:<!DOCUMENT html> head部分:放了一些相关的JS,title描述,然后就是meta表述了.比较有参考的如下 & ...
- HTML5 CSS Reset
最近在学习HTML和CSS,发现一个不错的模板,放于此处. /* html5doctor.com Reset Stylesheet v1.6.1 Last Updated: 2010-09-17 Au ...
- python字典转datafarm,pandas
# coding:utf-8 import json import pandas as pd with open("./article_file/all_article.json" ...
- 论参数self
此篇文章仅适用于py3.在py2中,a.fuc(x)中的参数x必须是 类a的实例对象,而py3则可以是任意对象.参考绑定方法和非绑定方法 当一个对象添加了一个方法,并且此方法的第一个参数为self,或 ...
- Java基础打包以及批处理命令运行
1.前期准备
- 微信小程序实现首页图片多种排版布局!
先来个效果图: 使用技术主要是flex布局,绝对定位布局,小程序前端页面开发,以及一些样式! 直接贴代码,都有详细注释,熟悉一下,方便以后小程序开发! wxml: <view class='in ...
- fuzz for test of the Net::HTTP::GET
use Net::HTTP::GET; % %0e%0f ' *%26 @.jpg>; my $count = 0; for @chars X @chars X @chars X @chars ...
- PWN入门
pwn ”Pwn”是一个黑客语法的俚语词 ,是指攻破设备或者系统 .发音类似“砰”,对黑客而言,这就是成功实施黑客攻击的声音——砰的一声,被“黑”的电脑或手机就被你操纵.以上是从百度百科上面抄的简介, ...
- 巧用PHP数组函数
2014年3月5日 08:48:39 情景:项目中需要根据传递来的参数的不同,使用不同的缓存 假如传递来的参数最多有这几个(在这个范围内,但是每次传过来的参数不确定): $arg = array( ' ...
- sass和scss相关知识
参考地址:http://www.imooc.com/learn/311 什么是css预处理器? CSS 预处理器定义了一种新的语言,其基本思想是,用一种专门的编程语言,为 CSS 增加了一些编程的特性 ...