日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理

發布時間:2023/12/4 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

B. Pasha and Phone

Time Limit: 20 Sec

Memory Limit: 256 MB

題目連接

http://codeforces.com/contest/595/problem/B

Description

Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits.

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.

?

Under two situations the player could score one point.

?1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won't get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.

?2. Ignoring the buoys and relying on dogfighting to get point. If you and your opponent meet in the same position, you can try to fight with your opponent to score one point. For the proposal of game balance, two players are not allowed to fight before buoy #2 is touched by anybody.

There are three types of players.

Speeder: As a player specializing in high speed movement, he/she tries to avoid dogfighting while attempting to gain points by touching buoys.
Fighter: As a player specializing in dogfighting, he/she always tries to fight with the opponent to score points. Since a fighter is slower than a speeder, it's difficult for him/her to score points by touching buoys when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.

There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting. Since Asuka is slower than Shion, she decides to fight with Shion for only one time during the match. It is also assumed that if Asuka and Shion touch the buoy in the same time, the point will be given to Asuka and Asuka could also fight with Shion at the buoy. We assume that in such scenario, the dogfighting must happen after the buoy is touched by Asuka or Shion.

The speed of Asuka is V1?m/s. The speed of Shion is V2?m/s. Is there any possibility for Asuka to win the match (to have higher score)?

Input

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).

?

Output

Print a single integer?— the number of good phone numbers of length n modulo 109?+?7.

?

Sample Input

6 2
38 56 49
7 3 4

Sample Output

8

HINT

?

題意

給你ai和bi,讓你找到有多少個k位數,使得這個k位數不以bi開頭且mod ai=0

處理n/k次,然后把所有的答案都乘起來

題解:

容斥定理,所有的方案數 - 以bi開頭的就好了

代碼

?

#include<iostream> #include<stdio.h> using namespace std; #define maxn 100005 const int mod = 1e9 + 7; long long a[maxn],b[maxn]; long long ten[20]; long long ans[maxn]; int main() {int n,k;scanf("%d%d",&n,&k);for(int i=1;i<=n/k;i++)scanf("%lld",&a[i]);for(int i=1;i<=n/k;i++)scanf("%lld",&b[i]);ten[0]=1;for(int i=1;i<=10;i++)ten[i]=ten[i-1]*10;long long tmp1,tmp2,tmp3;for(int i=1;i<=n/k;i++){tmp1 = (ten[k]-1)/a[i]+1;tmp2 = ((b[i]+1)*ten[k-1]-1)/a[i]+1;if(b[i]==0)ans[i]=tmp1-tmp2;else{tmp3 = ((b[i])*ten[k-1]-1)/a[i]+1;ans[i]=tmp1-tmp2+tmp3;}}long long Ans = 1;for(int i=1;i<=n/k;i++)Ans = (Ans * ans[i])%mod;printf("%lld\n",Ans); }

?

總結

以上是生活随笔為你收集整理的Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。