#C++初学记录(ACM8-6-cf-f题)

F. Vanya and Label

While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 1e9 + 7.

To represent the string as a number in numeral system with base 64 Vanya uses the following rules:
digits from '0' to '9' correspond to integers from 0 to 9;
letters from 'A' to 'Z' correspond to integers from 10 to 35;
letters from 'a' to 'z' correspond to integers from 36 to 61;
letter '-' correspond to integer 62;
letter '_' correspond to integer 63;

**Input** The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'. **Output** Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 1e9 + 7. ** Examples input** z **output** 3 **input** V_V **output** 9 **input** Codeforces **output** 130653412 **Note** For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia.

In the first sample, there are 3 possible solutions:

**
z&_ = 61&63 = 61 = z
_&z = 63&61 = 61 = z
z&z = 61&61 = 61 = z**
正确代码

#include<bits/stdc++.h>
using namespace std;
#define modd 1000000007
int main(){
	char a[100006];
	cin>>a;
	long long lena=strlen(a);
	long long ans=1;
	long long n;
	for(int i=0;i<lena;i++){
		
		n=0;
		
		if(a[i]>='0'&&a[i]<='9')
		n=a[i]-'0';
		
		if(a[i]>='A'&&a[i]<='Z')
		n=a[i]-'A'+10;
		
		if(a[i]>='a'&&a[i]<='z') 
		n=a[i]-'a'+36;
		
		if(a[i]=='-')
		n=62;
		
		if(a[i]=='_') 
		n=63;
		
		for(int j=0;j<6;j++){
			if(((n>>j)&1)==0){
				ans=(ans*3)%modd;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
} 

题目理解

给出一个字符串,字符串中可能含有1-9的数字,a-z的字母,A-Z的字母,然后将他们全部转化成题目给出的编码,得到编码后,通过程序进行判断有多少个字符组合通过AND(&)符运算后不会改变字符串中字符的编码。

相关知识点
本题完成需要读懂题目,判断字符串中编码不仅仅是将其化为ascll码,而是要根据题意进行初始编码后再进行化为二进制,其次二进制的判断是位移运算符与AND运算符结合完成的,具体代码为


		for(int j=0;j<6;j++){
			if(((n>>j)&1)==0){
				ans=(ans*3)%modd;
			}
		}

由题意得出最大代码为63的“_”,即不超过64位,因此二进制可以化为六位数正好小于2^6,到此代码编写与理解完成。

posted @ 2019-08-06 12:51  十魇  阅读(197)  评论(0编辑  收藏  举报
GenerateContentList