atcoder-077S - mall Multiple - 双向队列deque 和 向量数组vector
2017-11-05 10:24
309 查看
问题
Problem Statement
Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.Constraints
2≤K≤105K is an integer.
Input
Input is given from Standard Input in the following format:K
Output
Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K.Sample Input 1
6
Sample Output 1
3
12=6×2 yields the smallest sum.
Sample Input 2
41
Sample Output 2
5
11111=41×271 yields the smallest sum.
Sample Input 3
79992
Sample Output 3
36
双向队列
deque双向队列是一种双向开口的连续线性空间,可以高效的在头尾两端插入和删除元素,deque在接口上和vector非常相似,下面列出deque的常用成员函数:解题
#include<stdio.h> #include<iostream> #include<cmath> #include<cstring> #include<algorithm> #include<map> #include<vector> #include<queue> #include<stack> #include<deque> using namespace std; typedef long long LL; #define ms(a,b) memset(a,b,sizeof(a)) # define eps 1e-8 bool to(int &x, int y) { if (x > y) { x = y; return true; } return false; } int main() { int K; cin>>K; deque<int> q;//双向队列 q.push_back(1); vector<int> dp(K,1e9);//表示有K个值为1e9的数 dp[1] = 1; while (!q.empty()) { int u = q.front(); q.pop_front(); //int d = dp[u]; if (to(dp[u * 10 % K], dp[u])) { q.push_front(u * 10 % K); } if (to(dp[(u + 1) % K], dp[u] + 1)) { q.push_back((u + 1) % K); } } cout << dp[0] << endl; return 0; }
相关文章推荐
- STL系列之deque双端队列+vector向量容器
- vector(容器)、list(列表)、deque(双向队列)的区别与比较
- ArrayDeque利用数组建造的双向队列
- STL——deque 双向队列
- STL系列之一 deque双向队列
- STL系列之一 deque双向队列
- STL之deque双向队列
- STL系列之一 deque双向队列
- STL系列之一 deque双向队列
- STL系列之一 deque双向队列
- STL之deque双向队列
- STL系列之一 deque双向队列
- R语言中的vector(向量),array(数组)总结
- Python学习笔记-Day03 -第二部分(双向队列-deque和单向队列Queue)
- STL系列(4):Deque 双向队列
- java堆栈(Deque双向队列)应用之括号匹配
- STL—— deque双向队列
- STL --> deque双向队列
- STL系列之一 deque双向队列
- 双向队列集合 Deque