atcoder-077S
来源:互联网 发布:平安银行java外包 编辑:程序博客网 时间:2024/04/30 06:14
问题
Problem Statement
Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.
Constraints
2≤K≤105
K 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-8bool 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;}
阅读全文
0 0
- atcoder-077S
- AtCoder Regular Contest 061 DSnuke's Coloring
- Atcoder ARC061 E Snuke's Subway Trip
- AtCoder 077E gururu
- Atcoder ARC 077 C
- Atcoder ARC 077 D
- Atcoder ARC 077 E
- Atcoder ARC 077 F
- AtCoder Regular Contest 077
- AtCoder Regular Contest 077
- AtCoder
- AtCoder
- AtCoder
- AtCoder
- AtCoder
- Atcoder
- AtCoder Regular Contest 077-C
- AtCoder Regular Contest 077-D
- PAT --- 1023. 组个最小数 (20)
- 【数据分析】目标优化矩阵表确定权重
- 19.读书笔记收获不止Oracle之 索引MAX和MIN优化
- 关于adr指令的理解
- [AtCoder Beginner Contest 077]D-Small Multiple
- atcoder-077S
- 20.读书笔记收获不止Oracle之 索引回表和优化
- 21.读书笔记收获不止Oracle之 索引回表效率
- Leetcode 算法题07
- 编写c++程序过程中出现的错误 annonymous type with no linkage used to declare variable
- 22.读书笔记收获不止Oracle之 索引特性活用
- 二叉树的深度和广度优先遍历
- 用C语言协助办公_01 找出所有不对劲的人
- Servlet:相对路径、绝对路径以及路径跳转问题