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 ...
随机推荐
- 【问题收集·中级】关于XMPP使用Base传送图片
[问题收集·中级]关于XMPP使用Base传送图片 下面是我与博友的问答过程:并在最后链接附录了相应的文件: 博友问题: 16:35:38 他跟我说要 内容图片 base64编码 上传..博友问题 ...
- Android手机间无线互传功能探索及实现
年前研究了一下Android如何实现无线互传的功能,写了个小demo,最近无事,遂整理一下,与各位共享.前期调研发现,Android想要实现无线互传有以下几种技术:1,Bluetooth通行已久,简单 ...
- HttpClient与HttpUrlConnection下载速度比较
Android有两套http的API,刚开始使用网络编程时多少有些迷惑到底用哪个好呢?其实孰优孰劣无需再争论,google已经指出HttpUrlConnection是Android更优的选择,并在SD ...
- 002_CentOS-6.4-x86_64安装包的说明
http://mirrors.sohu.com/centos/6.6/isos/x86_64/?qq-pf-to=pcqq.group //souhu镜像下载地址 0_README.txt 25-Oc ...
- 关于sudo 权限被修改的解决方法
在用sudo安装文件的时候,出现如下错误提示: sudo: /etc/sudoers is world writable sudo: no valid sudoers sources found, q ...
- Ubuntu下pycharm安装
参考:http://blog.csdn.net/langb2014/article/details/51166782 http://www.cnblogs.com/zhcncn/p/4027025.h ...
- NOIp 2018 提高组
T1铺设道路 传送门 题目描述 春春是一名道路工程师,负责铺设一条长度为 $ n $ 的道路. 铺设道路的主要工作是填平下陷的地表.整段道路可以看作是 $ n $ 块首尾相连的区域,一开始,第 ii ...
- 【招聘】这一次,我们Hold住了世界杯
作为国内最大的云计算服务商,阿里云在视频领域拥有绝对的技术优势,全球范围内拥有1500多个CDN节点,带宽储备120多T,不仅为优酷.CNTV.CCTV5提供技术支撑,还承担了全网70%的世界杯流量. ...
- 【pytorch】pytorch学习笔记(一)
原文地址:https://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html 什么是pytorch? pytorch是一个基于p ...
- node.js获取请求参数的方法和文件上传
var http=require('http') var url=require('url') var qs=require('querystring') http.createServer(onRe ...