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,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...
随机推荐
- 【转】C++实现RTMP协议发送H.264编码及AAC编码的音视频
RTMP(Real Time Messaging Protocol)是专门用来传输音视频数据的流媒体协议,最初由Macromedia 公司创建,后来归Adobe公司所有,是一种私有协议,主要用来联系F ...
- java-四个线程修改一个变量
package 经典; public class 四个线程 { private int j=10; /** * @param args */ public static void main(Strin ...
- One Way Roads(搜索)
One Way Roads Time Limit:500MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- C#集合-队列
本文来自:http://www.cnblogs.com/yangyancheng/archive/2011/04/28/2031615.html 队列是其元素以先进先出(FIFO)的方式来处理的集合. ...
- DWZ主从结构计算
最终效果图: 首先我们需要修改一下主从结构的源码dwz.database.js,如下: function tdHtml(field){ var html='',suffix=''; if(field. ...
- application,session,cookie三者之间的区别和联系
application: 程序全局变量对象,对每个用户每个页面都有效 session: 用户全局变量,对于该用户的所有操作过程都有效 session主要是在服务器端用,一般对客户端不 ...
- ASP.NET通用权限组件思路设计
开篇 做任何系统都离不开和绕不过权限的控制,尤其是B/S系统工作原理的特殊性使得权限控制起来更为繁琐,所以就在想是否可以利用IIS的工作原理,在IIS处理客户端请求的某个入口或出口通过判断URL来达到 ...
- ASP.NET中分布式事务的使用
之前发表了一篇事务的存储过程,最近在做项目的时候遇到分布式事务,所有总结一下,跟大家分享和交流一下经验.首先说明为什么要分布式事务呢?先说说我在项目的哪里遇到分布式事务吧,我是在做网站后台开发的时候, ...
- A + B Problem II---hdu1002
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- android activity启动的时候隐藏软键盘
1.概述 android如果界面有EditText之类的跳软键盘的控件 在跳转到该界面是默认会跳出软键盘的. 更何况有些需求要直接需要获取焦点 <requestFocus /> 如果是E ...