#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,到此代码编写与理解完成。
#C++初学记录(ACM8-6-cf-f题)的更多相关文章
- 2013年山东省赛F题 Mountain Subsequences
2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...
- 做了一道cf水题
被一道cf水题卡了半天的时间,主要原因时自己不熟悉c++stl库的函数,本来一个可以用库解决的问题,我用c语言模拟了那个函数半天,结果还超时了. 题意大概就是,给定n个数,查询k次,每次查询过后,输出 ...
- 2017Summmer_上海金马五校 F题,G题,I题,K题,J题
以下题目均自己搜 F题 A序列 一开始真的没懂题目什么意思,还以为是要连续的子串,结果发现时序列,简直智障,知道题意之后,好久没搞LIS,有点忘了,复习一波以后,直接双向LIS,处理处两个数组L和R ...
- ACM-ICPC 2019南昌网络赛F题 Megumi With String
ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- B. Lost Number【CF交互题 暴力】
B. Lost Number[CF交互题 暴力] This is an interactive problem. Remember to flush your output while communi ...
- AtCoder Beginner Contest 215 F题题解
F - Dist Max 2 什么时候我才能突破\(F\)题的大关... 算了,不说了,看题. 简化题意:给定\(n\)个点的坐标,定义没两个点的距离为\(min(|x_i-x_j|,|y_i-y_j ...
- 【cf补题记录】Codeforces Round #608 (Div. 2)
比赛传送门 再次改下写博客的格式,以锻炼自己码字能力 A. Suits 题意:有四种材料,第一套西装需要 \(a\).\(d\) 各一件,卖 \(e\) 块:第二套西装需要 \(b\).\(c\).\ ...
- #C++初学记录ACM补题(D. Candies!)前缀和运算。
D - Candies! Consider a sequence of digits of length [a1,a2,-,a]. We perform the following operati ...
- 【cf补题记录】Codeforces Round #607 (Div. 2)
比赛传送门 这里推荐一位dalao的博客-- https://www.cnblogs.com/KisekiPurin2019/ A:字符串 B:贪心 A // https://codeforces.c ...
随机推荐
- 使用ABAP绘制可伸缩矢量图
Jerry去年的文章 动手使用ABAP Channel开发一些小工具,提升日常工作效率 里曾经介绍过一些用ABAP实现的可供娱乐的小程序,比如用古老的HPGL接口在SAPGUI里绘图: 关于如何用SA ...
- 【RAC】 RAC For W2K8R2 安装--grid的安装(四)
[RAC] RAC For W2K8R2 安装--grid的安装(四) 一.1 BLOG文档结构图 一.2 前言部分 一.2.1 导读 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学 ...
- Jenkins使用过程中注意事项
jenkins自动部署注意事项: 安装jenkins https://blog.csdn.net/qq_37372007/article/details/81586751 1.当提示错误ERROR: ...
- 判断OpenCV是否为共享库,Windows基于CMake编译Caffe需要opencv共享库
判断OpenCV是否为共享库,Windows基于CMake编译Caffe需要opencv共享库 TLDR 只考虑windows下opencv预编译包的情况. 对于opencv2.4.x系列,cmake ...
- python笔记--------一
作用域: 每个变量或函数都有自己的作用域. 每个函数都定义了一个命名空间,也称为作用域. 在最顶层有一个符号表会跟踪这一层所有的名称定义和和他们当前的绑定. 调用函数时,会建立一个新的符号表(常称为栈 ...
- GCC编译流程浅析
GCC-GCC编译流程浅析 序言 对于大多数程序员而言,大家都知道gcc是什么,但是如果不接触到linux平台下的开发,鲜有人真正了解gcc的编译流程,因为windows+IDE的开发模式简直是一条龙 ...
- 使用Gerrit发送测试邮件
使用Gerrit发送测试邮件 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装HTTP服务 1>.安装HTTP服务 [root@gerrit.yinzhengjie.o ...
- git拉取远程分支并切换到该分支
整理了五种方法,我常用最后一种,这五种方法(除了第4中已经写了fetch的步骤)执行前都需要执行git fetch来同步远程仓库 (1)git checkout -b 本地分支名 origin/远程分 ...
- Centos7-基本设置
设置hostname hostnamectl set-hostname ABC 查看网络连接 netstat/ss -lntcp 查找软件 rpm -ql python find /tmp/ -nam ...
- 微信小程序转百度小程序代码
听说百度小程序开始出现手机端搜索流量,作为SEO一员,必须搞他.但是又奈何之前做的都是微信小程序,所以用php写了一个微信小程序转百度小程序代码. 修改文件后缀名 .wxml转换为.swan .wxs ...