P2106 confidential intelligence
Problem DescriptionHY likes to chat with GJQ very much, while others are still struggling on the road of OI. In order not to disturb the students, they exchange the unified ciphertext, and the plaintext of the exchange of information is a non-empty sequence composed of 0 and 1. It consists of 0, 1, and several password letters, each of which represents a different 01 string.
For example, cipher text 011a0bf00a01. The key to password deciphering is to determine the meaning of each password.
After long-term statistical analysis, I now know the fixed length of each password. Now, the students who have suffered from the pain have intercepted the two ciphertexts S1 and S2 of the two, and know that S1 = S2, that is, the two ciphertexts represent the same Clear text. Your task is to help students analyze the given two ciphertexts and see how many possible plaintexts there are.
Input format Output formatM (indicating that there are M possible plaintexts)
Sample input100ad1
Cc1
4
a 2
d 3
c 4
b 50
Sample output2
promptThe length of the plain text is ≤ 10000, ensuring no high precision
This question is actually very water, use the same and merge the same position, then merge the position with the value 0 into a collection, the position with the value of 1 is merged into a collection, and then neither in the 0 collection nor in the collection. The number of sets in a set is the number of positions that cannot be determined. The answer is 2 n. However, there is no solution. If the last 0 set and 1 set are in a set, that means that a position is both 0 and 1, there is no solution.
Code:
#include"stdio.h"
#include《iostream》
#include"algorithm"
#include《cstring》
#include"vector"
#define N 55555
#define ll unsigned long long
Using namespace std;
Const ll T=40000;
String s1,s2;
Vector"ll"P[233];
Char A[233];
Ll n, L[233], sum1[N], sum2[N], F[N];
Bool mark[N];
Ll GF(ll x)
{
If(F[x]!=x)F[x]=GF(F[x]);
Return F[x];
}
Void Merge(ll x,ll y)
{
Ll fx=GF(x),fy=GF(y);
If(fx!=fy)F[fx]=fy;
}
Ll QM(ll a,ll b)
{
Ll ans=1;
While(b)
{
If(b&1)ans=ans*a;
b》"=1; a=a*a;
}
Return ans;
}
Int main()
{
Ll i,j,k,ans;ans=0;
Cin》s1》》2;
S1=“ â€+s1;s2=“ â€+s2;
Scanf("%lld",&n);
For(i=1;i“=n;i++)scanf(“%c %lldâ€,&A[i],&k), L[A[i]]=k;
For(i=1;i“=T;i++)F[i]=i;
For(i=1;i"s1.length();i++)
If(s1[i]=='0')sum1[i]=sum1[i-1]+1,Merge(sum1[i],T);
Else if(s1[i]=='1')sum1[i]=sum1[i-1]+1,Merge(sum1[i],T+1);
Else sum1[i]=sum1[i-1]+L[s1[i]],P[s1[i]].push_back(sum1[i-1]);
For(i=1;i"s2.length();i++)
If(s2[i]=='0')sum2[i]=sum2[i-1]+1,Merge(sum2[i],T);
Else if(s2[i]=='1')sum2[i]=sum2[i-1]+1,Merge(sum2[i],T+1);
Else sum2[i]=sum2[i-1]+L[s2[i]],P[s2[i]].push_back(sum2[i-1]);
For(i=1;i"=n;i++)
For(j=1;j"=L[A[i]];j++)
For(k=1;k"P[A[i]].size();k++)Merge(P[A[i]][k-1]+j,P[A[i]][k]+ j);
For(i=1;i"=sum1[s1.length()-1];i++)if(GF(i)!=GF(T)&&GF(i)!=GF(T+1)&&(!mark [GF(i)]))ans++,mark[GF(i)]=1;
If(GF(T)!=GF(T+1))printf("%lld",QM(2,ans));
Else printf("0");
}
Screw Terminal Connector,Pcb Screw Terminal,Screw Terminal Block Connector,Screw Type Terminal Blocks
Cixi Xinke Electronic Technology Co., Ltd. , https://www.cxxinke.com