Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

                        B. Pasha and Phone
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.

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 test(s)
input
6 2
38 56 49
7 3 4
output
8
input
8 2
1 22 3 44
5 4 3 2
output
32400


Note
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.

?

題意:將一個長度為n的phone number,分成長度為k的n/k給塊,如果任意一個塊(塊i)中的數字x的開頭數字不是b[i], 且x可以整除a[i],那么就稱這個phone number是 good number。問這樣的good number 有多少個!

思路:容斥原理。 塊 i : tot = 數字長度為k且可以整除a[i]的個數;

?bi_tot = 數字長度為k且開頭數字為b[i]且可以整除a[i]的個數 -?數字長度為k且開頭數字為(b[i]-1)且可以整除a[i]的個數

那么符合要求的數字個數 = tot - bi_tot;(b[i]>0)

#include<iostream> 
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define N 1000005
#define MOD 1000000007
using namespace std;
typedef __int64 LL;
int a[N];
int b[N];
int f[15];
void init(){f[0] = 1;for(LL i=1; i<10; ++i)f[i] = f[i-1] * 10;
}int main(){init(); int n, k;scanf("%d%d", &n, &k);int m = n/k;for(int i=1; i<=m; ++i)scanf("%d", &a[i]);for(int i=1; i<=m; ++i)scanf("%d", &b[i]);LL ans = 1;for(int i=1; i<=m; ++i){LL tot = (f[k]-1)/a[i] + 1;LL bi_tot0 = (f[k-1]-1)/a[i] + 1;//block的開頭是0, 即b[i]==0 LL bi_tot = (f[k-1]*(b[i]+1)-1)/a[i] - (f[k-1]*b[i]-1)/a[i];//block的開頭不是0 if(b[i] == 0) ans *= tot-bi_tot0;else ans *= tot-bi_tot;ans %= MOD;}printf("%I64d\n", ans);return 0;
}

?

C. Duff and Weight Lifting

Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of?i-th of them is?2^wi?pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.

Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights?2^a1,?...,?2^ak?if and only if there exists a non-negative integer?x?such that?2^a1?+?2^a2?+?...?+?2^ak?=?2^x, i. e. the sum of those numbers is a power of two.

Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.

Input

The first line of input contains integer?n?(1?≤?n?≤?106), the number of weights.

The second line contains?n?integers?w1,?...,?wn?separated by spaces (0?≤?wi?≤?106?for each?1?≤?i?≤?n), the powers of two forming the weights values.

Output

Print the minimum number of steps in a single line.

Sample test(s)
input
5
1 1 2 3 3
output
2
input
4
0 1 2 3
output
4
Note

In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.

In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.

題意:給定n個數w1, w2, w3,.......wn, 然后從這個n數中找出這樣的一個子序列a1,a2,a3....ak 使得 2^a1+2^a2.....+2^ak = 2^x, 然后可以刪除這個序列,

那么最少經過幾步可以全部將這n個數刪除!

思路:其實就是 二進制數 相加的過程,n個數對應n個二進制數,從最低位到最高位相加,得到最后的二進制數中 1 的個數就是答案!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
map<int, int, less<int> >mp;
int main(){int n;scanf("%d", &n);while(n--){int x;scanf("%d", &x);mp[x]++;}int ans = 0;for(map<int,int>::iterator it = mp.begin(); it!=mp.end(); ++it){if(it->second>1)mp[it->first + 1] += it->second / 2;if(it->second%2 != 0) ++ans;}printf("%d\n", ans);return 0;
}

?

轉載于:https://www.cnblogs.com/hujunzheng/p/4895835.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/531404.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/531404.shtml
英文地址,請注明出處:http://en.pswp.cn/news/531404.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

vmware中裝的ubuntu上不了網

本文章針對橋接方式進行講解&#xff0c;如果需要另外兩種連接方式請參考文末給出的鏈接 &#xff08;一&#xff09;問題 主機和虛擬機可以相互ping通&#xff0c;但是卻不能ping網址 &#xff08;二&#xff09;解決辦法 vmware為我們提供了三種網絡工作模式&#xff0c;…

document.getElementById()與 $()區別

document.getElementById()返回的是DOM對象&#xff0c;而$()返回的是jQuery對象 什么是jQuery對象&#xff1f; ---就是通過jQuery包裝DOM對象后產生的對象。jQuery對象是jQuery獨有的&#xff0c;其可以使用jQuery里的方法。 比如&#xff1a; $("#test").html() 意…

關于gedit的編碼問題

今天由于gedit的編碼格式導致LCD顯示屏的問題&#xff0c;開始沒有想到后來才發現&#xff0c;在這記錄一下 #include <stdio.h> #include <unistd.h> #include <stdio.h> #include <fcntl.h> #include <linux/fb.h> #include <sys/mman.h>…

c語言表白程序代碼

雙十一要到了&#xff0c;好激動啊&#xff01;&#xff01;&#xff01; 是時候準備出手了&#xff01; 花了一天的時間寫的表白代碼。 表示自己弱弱的..... 看了網上好多都是js寫的&#xff0c;感覺碉堡了&#xff01;js用的不熟&#xff0c;前端不好&#xff0c;java&#x…

tiny4412移植tslib庫

1、將tslib-1.4.tar.gz拷貝到虛擬機某個路徑進行解壓 2、進入解壓路徑tslib 3、執行#./autogen.sh 如果提示&#xff1a;./autogen.sh: 4: ./autogen.sh: autoreconf: not found 原因&#xff1a;沒有安裝automake工具, 解決辦法:需要安裝此工具&#xff1a; apt-get instal…

移植QT到tiny4412開發板

目錄&#xff08;一&#xff09; 環境準備&#xff08;二&#xff09; Qt源代碼下載&#xff08;三&#xff09; 移植tslib庫&#xff08;四&#xff09;操作流程1.解壓qt源碼包2.配置編譯環境3.生成Makefile4.編譯安裝5.安裝一些庫用來支持 qt6. 添加以下內容到開發板目錄下的…

c++面試常用知識(sizeof計算類的大小,虛擬繼承,重載,隱藏,覆蓋)

一. sizeof計算結構體 注&#xff1a;本機機器字長為64位 1.最普通的類和普通的繼承 #include<iostream> using namespace std;class Parent{ public:void fun(){cout<<"Parent fun"<<endl;} }; class Child : public Parent{ public:void fun(){…

嵌入式面試題(一)

目錄1 關鍵字volatile有什么含義&#xff1f;并給出三個不同的例子2. c和c中的struct有什么不同&#xff1f;3.進程和線程區別4.ARM流水線5.使用斷言6 .嵌入式系統的定義7 局部變量能否和全局變量重名&#xff1f;8 如何引用一個已經定義過的全局變量&#xff1f;9、全局變量可…

能ping通ip但無法ping通域名和localhost //ping: bad address 'www.baidu.com'

錯誤描述&#xff1a; ~ # ping localhost ping: bad address localhost原因&#xff0c;在/etc目錄下缺少hosts文件&#xff0c;將linux中的/etc hosts文件拷入即可 ~ # ping localhost PING localhost (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: seq0 ttl64 tim…

eclipse導入web項目之后項目中出現小紅叉解決辦法

項目中有小紅叉我遇到的最常見的情況&#xff1a; 1、項目代碼本身有問題。&#xff08;這個就不說了&#xff0c;解決錯誤就OK&#xff09; 2、項目中的jar包丟失。&#xff08;有時候eclipse打開時會出現jar包丟失的情況&#xff0c;關閉eclipse重新打開或者重新引入jar包就O…

arm開發板通過網線連接筆記本電腦上外網

需要工具&#xff1a;arm開發板&#xff0c;網線&#xff0c;一臺雙網卡的win7筆記本電腦&#xff08;筆記本電腦一般都是雙網卡&#xff09; 一、筆記本電腦需要先連上外網&#xff0c;可以連上家里的WIFI&#xff0c;或者手機開熱點&#xff08;本人未測試過連接手機的熱點&…

windows下實現Git在局域網使用

1.首先在主機A上創建一個文件夾用于存放你要公開的版本庫。然后進入這個文件夾&#xff0c;右鍵->Git create repository here&#xff0c;彈出的窗口中勾選Make it Bare&#xff01;之后將這個文件夾完全共享&#xff08;共享都會吧&#xff1f;注意權限要讓使用這個文件夾…

解決linux下QtCreator無法輸入中文的情況

安裝了QtCreator(Qt5.3.1自帶版本)后無法輸入中文&#xff0c;確切的說是無法打開輸入法。以前使用iBus輸入法的時候沒有這個問題&#xff0c;現在使用sougou輸入法才有的這個問題。 可以查看此文 http://www.cnblogs.com/oloroso/p/5114041.html 原因 有問題就得找原因&…

lintcode 滑動窗口的最大值(雙端隊列)

題目鏈接&#xff1a;http://www.lintcode.com/zh-cn/problem/sliding-window-maximum/# 滑動窗口的最大值 給出一個可能包含重復的整數數組&#xff0c;和一個大小為 k 的滑動窗口, 從左到右在數組中滑動這個窗口&#xff0c;找到數組中每個窗口內的最大值。 樣例 給出數組 [1…

你的main函數規范嗎?

在學習c語言的時候&#xff0c;有一個函數一直被我們使用&#xff0c;那就是main函數&#xff0c;但是你知道標準里面是怎么規定它的寫法嗎&#xff1f; 平時看見的main函數有下面這幾種&#xff1a; 1.int main(void){ }2.int main(){ }3.int main(int argc, char *argv[])…

lintcode 最長上升連續子序列 II(二維最長上升連續序列)

題目鏈接&#xff1a;http://www.lintcode.com/zh-cn/problem/longest-increasing-continuous-subsequence-ii/ 最長上升連續子序列 II 給定一個整數矩陣&#xff08;其中&#xff0c;有 n 行&#xff0c; m 列&#xff09;&#xff0c;請找出矩陣中的最長上升連續子序列。&a…

適用于Linux的Windows子系統WSL

以前使用的都是在虛擬機里安裝linux&#xff0c;最近才發現在win10提供了WSL(Windows Subsystem for Linux) &#xff0c;簡單來說就是可以在win10里面直接使用Linux。 &#xff08;一&#xff09;首先打開Microsoft Store , 搜索 Linux &#xff08;二&#xff09;選擇自己需…

jsp通過易寶方式實現在線支付

項目下載地址: https://github.com/hjzgg/OnlinePayment 參考&#xff1a;http://blog.csdn.net/jadyer/article/details/7380259?utm_sourcetuicool&utm_mediumreferral 效果圖1&#xff1a;請求界面 效果圖2&#xff1a;地支付請求和易寶之間建立連接之后跳轉到相應的銀…

permission denied是什么鬼?

問題&#xff1a;在PC端編譯了一個arm芯片的測試程序&#xff0c;出現了permission denied 解決辦法&#xff1a; 1.給文件賦予可執行權限 chmod ax xxx這是一般第一反應會想到的答案 2. 有時候已經有可執行權限&#xff0c;還是提示上面的錯誤此時要注意你的交叉編譯器是否正…

CSS中div覆蓋另一個div

將一個div覆蓋在另一個div上有兩種手段&#xff1a;一是設置margin為負值&#xff0c;二是設置絕對定位。 可以根個人情況設置z-index的值 1->position 為absolute的情況 <html> <head> <style> #div1{position:absolute;width:300px;height:300px;backgr…