题意:

  给定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

最新文章

  1. nodeJS接受post传过来的参数
  2. 时间格式转化 String2datestyle
  3. 多个App间传递数据
  4. Unity3D]引擎崩溃、异常、警告、BUG与提示总结及解决方法
  5. Combination Sum | &amp; || &amp; ||| &amp; IV
  6. 监听cell 滑动到 摸个分区
  7. 论文笔记之:Multiple Object Recognition With Visual Attention
  8. ASP.NET MVC ViewData/ViewBag 简单小结
  9. hihocoder 1082 然而沼跃鱼早就看穿了一切(字符串替换)
  10. jQuery 手风琴侧边菜单
  11. vim代码折叠功能
  12. CodeForces-748B
  13. fortran常用语句--读写带注释文档、动态数组等语法
  14. Python3使用AES加密的库函数PyCrypto、PyCryptodome
  15. 通过webservice(System.Data.OracleClient)调试oracle
  16. GOROOT、GOPATH、GOBIN
  17. Python之线程与进程
  18. enum 关键字
  19. CodeSmith 基础用法和例子
  20. urllib2特点--urllib2.build_opener对象接口

热门文章

  1. python编码问题——解决python3 UnicodeEncodeError: &#39;gbk&#39; codec can&#39;t encode character &#39;\xXX&#39; in position XX
  2. 【Android】System.exit(0) 退出程序
  3. hdoj 4712 Hamming Distance(靠人品过的)
  4. 基于spring的观察者模式
  5. AUTOSAR学习之RTE - 基本概念
  6. 学好C/C++编程,走遍天下都不怕
  7. 33行代码爬取妹子图片(bs4+urllib)
  8. ccf 201903-3 损坏的RAID5
  9. Jersey用户指南学习笔记1
  10. C++实现多组数据合并输出