题意:输入一串字符s,每个字符对应一个数字,求这个字符串&另一个字符串等于s本身的数量,字符s和满足要求的另一个字符在&前后位置算两种。
思路:看官方题解的
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<iostream>
#define FIN freopen("input.txt","r",stdin)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
string s;
string index;
ll symbol_num[305];
int main()
{
for(char i='0'; i<='9'; i++)
index.push_back(i);
for(char i='A'; i<='Z'; i++)
index.push_back(i);
for(char i='a'; i<='z'; i++)
index.push_back(i);
index.push_back('-');
index.push_back('_');
for(int i=0; i<64; i++)
{
symbol_num[index[i]]=i;
}
//FIN;
while(cin>>s)
{
ll ans=1;
for(int i=0; i<s.size(); i++)
{
ll x=symbol_num[s[i]];
for(int j=0; j<6; j++)
if((x&(1<<j))==0) ans=(ans*3)%MOD;
}
cout<<ans<<endl;
}
return 0;
}
本文介绍了一种通过位运算计算特定字符串与另一未知字符串按位与等于原字符串的可能组合数量的方法。通过预设字符与对应的数值关系,利用位运算统计不同字符组合的可能性。
507

被折叠的 条评论
为什么被折叠?



