Codeforces Round #355 (Div. 2)-C
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 sand 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 109 + 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.
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 '_'.
Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo109 + 7.
z
3
V_V
9
Codeforces
130653412
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
题意:给定一个字符串,每个字符定义如上说明。然后问有多少长度和给定的串长度相同并且与给定的串位与之后还是等于给定的串。 输出结果MOD 1e9+7
思路:考虑每个字符,因为有位于运算所以先把字符对应的数字转换为二进制,可以发现0-63只需6位二进制表示。然后考虑每一位i[0-5],如果该位为1,那么要使得&后与原串相同,那么对应该位置只能1[1&1=1], 但是如果该位为0,那么对应位置就可以是0&0,0&1,1&0共3种。最后根据组合乘法计算总数。
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
#include<bitset>
using namespace std;
typedef long long int LL;
#define INF 0x3f3f3f3f
const int MAXN = + ;
const int MOD = 1e9 + ;
char str[MAXN];
int getnum(char ch){
int num;
if (ch >= ''&&ch <= ''){
num = ch - '';
}
else if (ch >= 'A'&&ch <= 'Z'){
num = (ch - 'A') + ;
}
else if (ch >= 'a'&&ch <= 'z'){
num = (ch - 'a') + ;
}
else if (ch == '-'){
num = ;
}
else{
num = ;
}
return num;
}
LL powmod(LL x, LL n){
LL ans = ;
while (n){
if (n & ){
ans = (ans*x)%MOD;
}
x = (x*x)%MOD;
n >>= ;
}
return ans;
}
int main(){
while (~scanf("%s", str)){
LL ans = ; int len = strlen(str);
for (int i = ; i < len; i++){
bitset<> num(getnum(str[i]));
for (int j = ; j < ; j++){
if (num[j] == ){
ans++;
}
}
}
printf("%I64d\n", powmod(,ans)%MOD);
}
return ;
}
Codeforces Round #355 (Div. 2)-C的更多相关文章
- Codeforces Round #355 (Div. 2)-B
B. Vanya and Food Processor 题目链接:http://codeforces.com/contest/677/problem/B Vanya smashes potato in ...
- Codeforces Round #355 (Div. 2)-A
A. Vanya and Fence 题目连接:http://codeforces.com/contest/677/problem/A Vanya and his friends are walkin ...
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure dp+分块
题目链接: http://codeforces.com/contest/677/problem/D 题意: 让你求最短的从start->...->1->...->2->. ...
- E. Vanya and Balloons Codeforces Round #355 (Div. 2)
http://codeforces.com/contest/677/problem/E 题意:有n*n矩形,每个格子有一个值(0.1.2.3),你可以在矩形里画一个十字(‘+’形或‘x’形),十字的四 ...
- D. Vanya and Treasure Codeforces Round #355 (Div. 2)
http://codeforces.com/contest/677/problem/D 建颗新树,节点元素包含r.c.dis,第i层包含拥有编号为i的钥匙的所有节点.用i-1层更新i层,逐层更新到底层 ...
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure 分治暴力
D. Vanya and Treasure 题目连接: http://www.codeforces.com/contest/677/problem/D Description Vanya is in ...
- Codeforces Round #355 (Div. 2) C. Vanya and Label 水题
C. Vanya and Label 题目连接: http://www.codeforces.com/contest/677/problem/C Description While walking d ...
- Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题
B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
随机推荐
- 为Kindeditor控件添加图片自动上传功能
Kindeditor是一款功能强大的开源在线HTML编辑器,支持所见即所得的编辑效果.它使用JavaScript编写,可以无缝地与多个不同的语言环境进行集成,如.NET.PHP.ASP.Java等.官 ...
- 【leetcode】Text Justification(hard) ☆
Given an array of words and a length L, format the text such that each line has exactly L characters ...
- yii压缩
application\components\controller.php protected function afterRender($view, &$output) { if(Yii:: ...
- NodeVisitor的使用-遍历Geode节点并在它与父节点之间添加一个LOD节点
#include <osg\NodeVisitor>#include <osg\MatrixTransform>#include <osg\PagedLOD>#in ...
- WaxPatch中demo注意问题
问题一 https://github.com/mmin18/WaxPatch网址中提供的demo是可以运行,但是存在一个问题,如果把patch.zip换成自己的并且上传到自己的服务器(github), ...
- 【2016-09-16】UbuntuServer14.04或更高版本安装问题记录
出于项目需要,我们的Qt程序需要运行在 1. Windows/Linux-X86平台(CPU为常见的桌面级CPU如G3220.I3等): 2. Windows/Linux-X86低功耗平台(CPU为I ...
- Redis内存管理(一)
Redis数据库的内存管理函数有关的文件为:zmalloc.h和zmalloc.c. Redis作者在编写内存管理模块时考虑到了查看系统内是否安装了TCMalloc或者Jemalloc模块,这两个是已 ...
- Oracle读写分离架构
读写分离是架构分布式系统的一个重要思想.不少系统整体处理能力并不能同业务的增长保持同步,因此势必会带来瓶颈,单纯的升级硬件并不能一劳永逸.针对业务类型特点,需要从架构模式上进行一系列的调整,比如业务模 ...
- mybatis配置问题
//当构造函数有多个参数时,可以使用constructor-arg标签的index属性,index属性的值从0开始. <bean id="sqlSession" class= ...
- NYOJ题目813对决
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAALRCAIAAAAiJ3lxAAAgAElEQVR4nO3dPW7jSgMu6LsJ516IYy