#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 ...
随机推荐
- Vue学习之Babel配置(十六)
一.Babel: (官网:https://www.babeljs.cn/docs/) 1.Babel 是一个 JavaScript 编译器: 2.Babel 是一个工具链,主要用于将 ECMAScr ...
- JavaScript之鼠标事件
事件三要素: 事件源.事件类型(点击onclick)=function(){ 事件触发后执行的代码 } 案例: function abb(a){ return document.getElementB ...
- Git查看某一个文件的历史提交信息
工作中我们有时候想要查看某一个文件的历史提交版本,] 还想看都修改过那些内容,那么这两个简单的命令就会帮到你了, 话不多说,comeBaby...... 1,首先查看一个文件的历史提交信息 git l ...
- 升级tinyhttpd-0.1.0,让其支持网页显示图像
tinyhttpd是学习http协议非常好的工具,但是由于其过于简单,不支持在网页上显示图片,所以我改了一些代码,让tinyhttpd可以现实图像,供新手一起学习和熟悉http协议,ubuntu14. ...
- C#MongDB数据库取某时间段内的数据
BsonDocument bsonDoc = new BsonDocument(); bsonDoc.Add("TimeData", new BsonDocument() { { ...
- Flask整合WebLoader 用于大附件拆分上传再合并
博客:https://blog.csdn.net/jinixin/article/details/77545140 github:https://github.com/jinixin/upload-d ...
- Flask入门到放弃(五)—— 蓝图
转载请在文章开头附上原文链接地址:https://www.cnblogs.com/Sunzz/p/10980094.html 蓝图 Blueprint 模块化 随着flask程序越来越复杂,我们需要对 ...
- Mysql InnoDB行锁不使用索引锁表的时候会锁整张表
原文:http://www.thinkphp.cn/topic/41577.html 如果使用针对InnoDB的表使用行锁,被锁定字段不是主键,也没有针对它建立索引的话.行锁锁定的也是整张表.锁整张表 ...
- 【转】libgo
原文:https://blog.csdn.net/libaineu2004/article/details/80554870 ------------------------------------- ...
- LG4781 【模板】拉格朗日插值 和 JLOI2016 成绩比较
[模板]拉格朗日插值 题目描述 由小学知识可知,$n$个点$(x_i,y_i)$可以唯一地确定一个多项式 现在,给定$n$个点,请你确定这个多项式,并将$k$代入求值 求出的值对$998244353$ ...