Pasha and Phone(思维)
- Pasha and Phone
1 second
256 megabytes
standard input
standard output
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly ndigits.
Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer.
To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1·10k - 1 + c2·10k - 2 + ... + ck.
Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7.
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k.
The second line of the input contains n / k space-separated positive integers — sequence a1, a2, ..., an / k (1 ≤ ai < 10k).
The third line of the input contains n / k space-separated positive integers — sequence b1, b2, ..., bn / k (0 ≤ bi ≤ 9).
Print a single integer — the number of good phone numbers of length n modulo 109 + 7.
6 2 38 56 49 7 3 4
8
8 2 1 22 3 44 5 4 3 2
32400
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
题解:小明要记电话号码了,给两个整数n,k,接下来是两个数组,有n/k个元素,让找是a数组对应块的倍数,又不能是b[i]开头的电话号的种类数;
很容易想到分成k块,分别找对应块的种类数;想着就去做了,假设k=2;b[i]=5,当对应块是5的时候也是符合的;因为是05,0开头的,错了几次,好像cf里面没有log
函数还是别的原因,我用log10(x)取小数找首数字的方法老是出问题,自己编译器上就没事,但是最后发现如果能用也会超时;暴力肯定解决不了;
因为是倍数;每个块里面可能有pow(10,k)个数,直接求出是a[i]倍数数字的个数,再减去b[i]**开头里面所占a[i]倍数的个数就是答案了;由于b[i]可能为0;所以
还要单独判断b[i]=0的情况,b[i]**开头里面所占a[i]倍数的个数就是b[i]+1开头所占a[i]倍数的个数减去b[i]开头所占a[i]的个数;
有点麻烦,需要考虑全面;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define P_ printf(" ")
#define mem(x,y) memset(x,y,sizeof(x))
typedef __int64 LL;
const int MAXN=;
const int MOD=1e9+;
int a[MAXN],b[MAXN],c[MAXN];
int main(){
int n,k;
while(~scanf("%d%d",&n,&k)){
mem(c,);
int p[];p[]=;
for(int i=;i<;i++)p[i]=p[i-]*;
for(int i=;i<n/k;i++)SI(a[i]);
for(int j=;j<n/k;j++)SI(b[j]);
for(int i=;i<n/k;i++){
if(a[i]==){
if(b[i]!=)c[i]++;continue;
}
/*
else for(int j=0;;j++){
if(j*a[i]>=p[k])break;
//int t=pow(10,log10(1.0*j*a[i])-(int)log10(1.0*j*a[i]));
if(j*a[i]/p[k-1]!=b[i])c[i]++;
}
*/
int x1,x2,x3;
x1=(p[k]-)/a[i]+;
x2=(p[k-]-)/a[i]+;
x3=(p[k-]*(b[i]+)-)/a[i]-(p[k-]*b[i]-)/a[i];
if(b[i]==)c[i]=x1-x2;
else c[i]=x1-x3;
}
LL ans=;
for(int i=;i<n/k;i++){
ans=ans*c[i]%MOD;
}
printf("%I64d\n",ans);
}
return ;
}
Pasha and Phone(思维)的更多相关文章
- Pasha and String(思维,技巧)
Pasha and String Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- Photoshop、Illustrator思维导图笔记
半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.
- CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维
前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...
- 计算机程序的思维逻辑 (8) - char的真正含义
看似简单的char 通过前两节,我们应该对字符和文本的编码和乱码有了一个清晰的认识,但前两节都是与编程语言无关的,我们还是不知道怎么在程序中处理字符和文本. 本节讨论在Java中进行字符处理的基础 - ...
- 计算机程序的思维逻辑 (29) - 剖析String
上节介绍了单个字符的封装类Character,本节介绍字符串类.字符串操作大概是计算机程序中最常见的操作了,Java中表示字符串的类是String,本节就来详细介绍String. 字符串的基本使用是比 ...
- 计算机程序的思维逻辑 (31) - 剖析Arrays
数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...
- 计算机程序的思维逻辑 (33) - Joda-Time
Joda-Time上节介绍了JDK API中的日期和时间类,我们提到了JDK API的一些不足,并提到,实践中有一个广泛使用的日期和时间类库,Joda-Time,本节我们就来介绍Joda-Time.俗 ...
- 计算机程序的思维逻辑 (53) - 剖析Collections - 算法
之前几节介绍了各种具体容器类和抽象容器类,上节我们提到,Java中有一个类Collections,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...
随机推荐
- 探索PHP+Nginx(二) 安装PHP
首先,我们简单了解一下什么是PHP,PHP(Hypertext Preprocessor 超文本预处理器) 和Java语言一样,PHP也是属于高级语言,并不能直接在操作系统上运行.Java运行需要虚拟 ...
- hdu 2202 最大三角形_凸包模板
题意:略 思路:直接套用凸包模板 #include <iostream> #include <cstdio> #include <cmath> #include & ...
- Java对象在JVM中的生命周期
当你通过new语句创建一个java对象时,JVM就会为这个对象分配一块内存空间,只要这个对象被引用变量引用了,那么这个对象就会一直驻留在内存中,否则,它就会结束生命周期,JVM会在合适的时 ...
- java值传递
Java使用按值传递的函数调用方式,这往往使我感到迷惑.因为在基础数据类型和对象的传递上,我就会纠结于到底是按值传递,还是按引用传递.其实经过学习,Java在任何地方,都一直发挥着按值传递的本色. 首 ...
- ASP.NET,Razor语句中@符号的意义
比较下面两段代码的区别: <td> @if (item.ModifyTime.HasValue) { @item.ModifyTime.GetValueOrDefault().ToStri ...
- 在sql server中怎样获得正在执行的Sql查询
方法1:使用DBCC inputbuffer(spid) 使用SP_WHO获得SPID,然后再执行上面的DBCC command,参见下图 执行一段sql语句 打开另一个query窗口并执行SP_WH ...
- rpm方式安装MySQL-5.6
1. 卸载系统原有的mysql-libs rpm -e [name] --nodeps 2. 安装MySQL rpm -ivh MySQL-server-XXXXXX rpm -ivh MySQL-c ...
- study notes: high performance linux server programming
1:linux网络API分为:socker地址API,socker基础API,网络信息API 1,socker地址API:包含IP地址和端口(ip, port).表示TCP通信的一端. 2,socke ...
- IE10以下placeholder不兼容
做页面的时候在谷歌中是显示的,但是换了IE之后总是不显示,一个文本框还好,如果有多个的话,如图: 添加以下一段Jquery代码: <script> var JPlaceHolder = { ...
- 检测delphi的程序的内存泄漏
在主窗体的FormCreate 加入ReportMemoryLeaksOnShutdown := True;