CodeForces 595B
题目链接:
http://codeforces.com/problemset/problem/595/B
题意:
有一个n位的电话号码,每位电话号码将分成n/k段,每段均为k个数,求出满足以下要求的电话号码个数
1)第i段可以整除a[i];
2)第i段不能以数字b[i]开头。
解题思路:
1、 第i段能被a[i]整除的的个数z=(10^k-1)/a[i]+1;
2、 能被a[i]整除但以b[i]开头的个数y有:设 MIN=b[i]*10^(k-1),MAX=(b[i]+1)*10^(k-1)-1;
①如果MIN/a[i]*a[i]=MIN, 则y=(MAX-MIN)/a[i]+1;
②如果①条件不满足,如果(MIN/a[i]+1)*a[i]<=MAX, 则y=(MAX-(MIN/a[i]+1)*a[i])/a[i]+1;
通过1和2可以得出第i段满足的号码个数为c[i]=z-y;将每一段满足情况的个数求出来,将它们乘起来就可以求出所要答案。
//借鉴了大神的思路
程序代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
#define LL long long
const int M=;
LL mod=;
LL a[M],b[M],num[M];
LL n,k,sum,m,cnt; void init()
{
for(LL i=;i<=k;i++)
cnt*=;
m=cnt/;
for(int i=;i<n/k;i++)
scanf("%d",&a[i]);
for(LL i=;i<n/k;i++)
scanf("%d",&b[i]);
} void work()
{
for(LL i=;i<n/k;i++)
{
num[i]=(cnt-)/a[i]+;
LL MAX=(b[i]+)*m-;
LL MIN=b[i]*m;
LL temp=MIN/a[i];
if(temp*a[i]==MIN)
num[i]-=(MAX-MIN)/a[i]+;
else if((temp+)*a[i]<=MAX)
{
MIN=(temp+)*a[i];
num[i]-=(MAX-MIN)/a[i]+;
}
}
}
int main()
{
sum=cnt=;
cin>>n>>k;
init();
work(); for(LL i=;i<n/k;i++)
sum=((num[i]%mod)*sum)%mod; printf("%lld\n",sum%mod);
return ;
}
CodeForces 595B的更多相关文章
- Codeforces 595B - Pasha and Phone
595B - Pasha and Phone 代码: #include<bits/stdc++.h> using namespace std; #define ll long long # ...
- Codeforces 595B. Pasha and Phone 容斥
B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- 屏蔽Codeforces做题时的Problem tags提示
当在Codeforces上做题的时,有时会无意撇到右侧的Problem tags边栏,但是原本并不希望能够看到它. 能否把它屏蔽了呢?答案是显然的,我们只需要加一段很短的CSS即可. span.tag ...
- 介绍一个小工具 Linqer
http://www.cnblogs.com/huangxincheng/archive/2011/05/12/2044990.html
- UITableViewCell 添加长按手势
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self actio ...
- OpenCV2.4.9 & Visual Studio 2010 环境配置篇
1. 准备工作 1.1. 安装 Visual Studio 2010, 需要安装 VC++ 相关功能.具体可求助度娘. 1.2. 下载 OpenCV 2.4.9 For Windows:https:/ ...
- 【POJ2752】【KMP】Seek the Name, Seek the Fame
Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...
- JQuery对单选框,复选框,下拉菜单的操作
JSP <%@ page language="java" import="java.util.*" pageEncoding="utf-8&qu ...
- 根据打开页面加载不同Js
根据打开页面加载不同Js //根据打开页面加载不同JS $(document).ready(function(){ var href = document.URL; /*获取当前页面的URL*/ if ...
- [Winfrom] 捕获窗体最大化、最小化和关闭按钮的事件
const int WM_SYSCOMMAND = 0x112;const int SC_CLOSE = 0xF060;const int SC_MINIMIZE = 0xF020;const int ...
- TatukGIS - GisDefs - ChangeDir 函数
函数名称 ChangeDir 所在单元 GisDefs 函数原型 function ChangeDir(const _path: String): String; 函数说明 如果 _path ...
- JQuery重要知识点
jQuery基本选择器----包括ID选择器,标签选择器,类选择器,通配选择器和组选择器5种 a. ID选择器: $("#id") b. 标签选择器:$("element ...