#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 ...
随机推荐
- hbuilder 热更新
记录下Hbuilder做热更新的功能. 首先是获取本地的版本与服务器的版本对比.服务器的版本大于本地的版本才进行更新.获取本地版本的方法 plus.runtime.getProperty(plus.r ...
- unittest管理接口用例(数据分离-读取excel)
1.简单读取 #coding=utf-8 #调用封装好的excel读取公共方法 from python_API.common.ReadExcel import ReadExcel import req ...
- C#-将照片存入到SQL SERVER
将存照片的字段设为image类型. using System; using System.Collections.Generic; using System.ComponentModel; using ...
- ondblclick和dblclick区别
1.ondblclick是一个HTML DOM Event 对象,没有jquery也可以触发这个事件的,使用方法例如 1 <button ondblclick="xxx"&g ...
- Linux基础命令-查看基本硬件信息
Linux基础命令-查看基本硬件信息 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看CPU信息 [root@node101.yinzhengjie.org.cn ~]# l ...
- 在本地调用hadoop的api
第一次在本地运行Java代码,调用hadoop的hdfs的api接口,遇到下面的问题: 1.HADOOP_HOME and hadoop.home.dir are unset 解决办法:在本地安装配置 ...
- windows10访问ftp中文乱码怎么办?
windows10访问ftp中文乱码怎么办? 打开控制面板 选择时间和区域 选择更改数字格式 点击管理并点击更改系统区域设置 打勾
- 正则爬取京东商品信息并打包成.exe可执行程序。
本文爬取内容,输入要搜索的关键字可自动爬取京东网站上相关商品的店铺名称,商品名称,价格,爬取100页(共100页) 代码如下: import requests import re # 请求头 head ...
- Codeforces H. Malek Dance Club(找规律)
题目描述: Malek Dance Club time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Integer面试连环炮以及源码分析
场景: 昨天有位朋友去面试,我问他面试问了哪些问题,其中问了Integer相关的问题,以下就是面试官问的问题,还有一些是我对此做了扩展. 问:两个new Integer 128相等吗? 答:不.因 ...