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 ... 
随机推荐
- sass的核心知识及使用
			sass的官方链接地址:htpp://sass-lang.com 参考链接地址:http://www.haorooms.com/post/sass_css 1. 基础语法 1.1 变量 SASS允许使 ... 
- Selenium模拟登陆百度贴吧
			Selenium模拟登陆百度贴吧 from selenium import webdriver from time import sleep from selenium.webdriver.commo ... 
- python虚拟环境完美部署
			一.前言 预处理 建议仔细看完本文章之后在进行操作,避免失误,本环境可以用于生产环境,有利于生产环境python之间的环境隔离,互相不会产生环境冲突:pyenv和pyenv-virtualenv可以完 ... 
- 【kafka】一、消息队列
			在高并发的应用场景中,由于来不及同步处理请求,接收到的请求往往会发生阻塞.例如,大量的插入.更新请求同时到达数据库,这会导致行或表被锁住,最后会因为请求堆积过多而触发“连接数过多的异常” 的错误.因此 ... 
- 【算法】【排序】【交换类】快速排序QuickSort
			#include<stdio.h> //快速排序 int main(){ ,,,,,,,,}; +; //基准指针 ; //慢指针 int* j=a; //快指针 int QS(int* ... 
- 【游记】NOIP2018初赛
			声明 本文最初的版本创建之时,本人甚至只是个电脑的小白,因而不太会用电脑编辑文字,最初的版本写在一个Word文档里,被随意的丢弃在我杂乱无比的网盘的某一个角落,直到我决定整理自己的成长历程,将散落的游 ... 
- Go中的文件读写
			在 Go 语言中,文件使用指向 os.File 类型的指针来表示的,也叫做文件句柄 .我们来看一下os包的使用方式. 1.读取文件 os包提供了两种打开文件的方法: Open(name string) ... 
- 从零开发一款自己的小程序UI组件库(二)
			写在前面:从零开发一款自己的小程序UI组件库(一) 上节我们讲到初始化组件库模板.模板文件概述.模板上传npm以及npm包文件下载至本地并运用到项目.这节我们继续,内容主要有基础UI组件库的搭建(bu ... 
- 原生JavaScript(js)手把手教你写轮播图插件(banner)
			---恢复内容开始--- 1.轮播图插件 1.什么是插件: 为已有的程序增加功能 2.插件的特点(为什么要做成一个插件)与注意事项: 1.通用性,可移植性强 2.兼容性:不会对其他代码产生影响 3.创 ... 
- sleep(),yield(),join(),wait()
			sleep(),yield(),join(),wait() sleep() sleep是Thread类的静态方法,在指定的时间内让当前线程暂停执行,但不会释放锁标志 也就是使线程进入阻塞状态 wait ... 
