Codeforces Round #506 (Div. 3) 1029 D. Concatenated Multiples
题意:
给定n个数字,和一个模数k,从中选出两个数,直接拼接,问拼接成的数字是k的倍数的组合有多少个。
思路:
对于a,b两个数,假定len = length of (b),那么a,b满足条件就是a * (len个10) + b 是k的倍数,相当于a * (len个10)% k + b % k = k;
那么我们可以预处理出每个数字%k的结果,用map计数。然后枚举每个数字,每个数字都有10种可能,因为len最大为10。每一次查找map中的数字要用find函数,不要用【】运算,find是二分,【】查找的复杂度高。
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set> using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
const double PI=acos(-1.0); template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
// #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------showtime----------------------*/
const int maxn = 2e5+;
ll a[maxn],lo[maxn];
map<ll,ll>mp[];
ll n,k;
int main(){
scanf("%I64d%I64d", &n, &k);
for(int i=; i<=n; i++){ scanf("%I64d", &a[i]);
ll tmp = 1ll*a[i],len = ;
while(tmp > ){
tmp/=;
len++;
}
// debug(len);
lo[i] = len;
mp[len][a[i]%k]++; }
ll ans = ;
for(int i=; i<=n; i++){
ll tmp = 1ll * a[i];
// debug(tmp);
for(int j=; j<=; j++){
tmp = (tmp * 10ll) % k;
ll c = (k-tmp);
if(c >= k) c = c % k;
//ans += mp[j][c];
auto po = mp[j].find(c);
if (po != mp[j].end()) ans += po->se;
if(lo[i] == j && a[i]%k == c)ans--;
}
}
printf("%I64d\n",ans); return ;
}
CF 1029D
Codeforces Round #506 (Div. 3) 1029 D. Concatenated Multiples的更多相关文章
- Codeforces Round #506 (Div. 3) 1029 F. Multicolored Markers
CF-1029F 题意: a,b个小正方形构造一个矩形,大小为(a+b),并且要求其中要么a个小正方形是矩形,要么b个小正方形是矩形. 思路: 之前在想要分a,b是否为奇数讨论,后来发现根本不需要.只 ...
- Codeforces Round #506 (Div. 3) 题解
Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...
- Codeforces Round #506 (Div. 3) D-F
Codeforces Round #506 (Div. 3) (中等难度) 自己的做题速度大概只尝试了D题,不过TLE D. Concatenated Multiples 题意 数组a[],长度n,给 ...
- Codeforces Round #506 (Div. 3) E
Codeforces Round #506 (Div. 3) E dfs+贪心 #include<bits/stdc++.h> using namespace std; typedef l ...
- Codeforces Round #506 (Div. 3) D. Concatenated Multiples
D. Concatenated Multiples You are given an array aa, consisting of nn positive integers. Let's call ...
- Codeforces Round #506 (Div. 3) - D. Concatenated Multiples(思维拼接求是否为k的倍数)
题意 给你N个数字和一个K,问一共有几种拼接数字的方式使得到的数字是K的倍数,拼接:“234”和“123”拼接得到“234123” 分析: N <= 2e5,简单的暴力O(N^2)枚举肯定超时 ...
- Codeforces Round #506 (Div. 3)
题解: div3水的没有什么意思 abc就不说了 d题比较显然的就是用hash 但是不能直接搞 所以我们要枚举他后面那个数的位数 然后用map判断就可以了 刚开始没搞清楚数据范围写了快速乘竟然被hac ...
- Codeforces Round #506 (Div. 3) C. Maximal Intersection
C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- 【Codeforces Round #506 (Div. 3) 】
A:https://www.cnblogs.com/myx12345/p/9844334.html B:https://www.cnblogs.com/myx12345/p/9844368.html ...
随机推荐
- vue history模式下出现空白页情况
问题描述: vue搭建的项目,路由一直用的hash模式,所以url中都会带有一个“#”号.现在想要去掉“#”,于是使用history模式 { mode: 'history' },代码如下: imp ...
- 【iOS】PLA 3.3.12
发件人 Apple Program License Agreement PLA We found that your app uses the Advertising Identifier but d ...
- 【Spring源码解析】—— 委派模式的理解和使用
一.什么是委派模式 委派模式,是指什么呢?从字面含义理解,委派就是委托安排的意思,委派模式就是在做具体某件事情的过程中,交给其他人来做,这个事件就是在我的完整链路上的一部分,但是复杂度较高的情况下或者 ...
- Python中的inf与nan
Python中可以用如下方式表示正负无穷 >>> float('inf') # 正无穷,inf不区分大小写,float('InF')一样可以. inf >>> fl ...
- 经典SQL(sqlServer)
一.基础 .说明:创建新表create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..) .分组: ...
- what is the CCA?
Clear Channel Assessment (CCA) is one of two carrier sense mechanisms in WLAN (or WiFi). It is defin ...
- css实现左边高度自适应右边高度
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 统计学习方法—SVM推导
目录 SVM 1. 定义 1.1 函数间隔和几何间隔 1.2 间隔最大化 2. 线性可分SVM 2.1 对偶问题 2.2 序列最小最优算法(SMO) 3. 线性不可分SVM 3.1 松弛变量 3.2 ...
- Tomcat源码分析 (三)----- 生命周期机制 Lifecycle
Tomcat里面有各种各样的组件,每个组件各司其职,组件之间又相互协作共同完成web服务器这样的工程.在这些组件之上,Lifecycle(生命周期机制)至关重要!在学习各个组件之前,我们需要看看Lif ...
- Redis的分布式和主备配置调研
目前Redis实现集群的方法主要是采用一致性哈稀分片(Shard),将不同的key分配到不同的redis server上,达到横向扩展的目的. 对于一致性哈稀分片的算法,Jedis-2.0.0已经提供 ...