Atcoder arc 084 D
来源:互联网 发布:分布式系统 云计算 编辑:程序博客网 时间:2024/06/01 21:25
题目链接:http://arc084.contest.atcoder.jp/tasks/arc084_b
D - Small Multiple
Time limit : 2sec / Memory limit : 256MB
Score : 700 points
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
Copy
6
Sample Output 1
Copy
3
12=6×2 yields the smallest sum.
Sample Input 2
Copy
41
Sample Output 2
Copy
5
11111=41×271 yields the smallest sum.
Sample Input 3
Copy
79992
Sample Output 3
Copy
36
解析:原来用暴力一直WA,比赛结束后看别人的代码,才知道可以用到抽屉原理,还是第一次接触双向队列(既可以当栈又可以当队列)
代码:
#include<stdio.h>#include<algorithm>#include<string.h>#include<queue>using namespace std; int vis[100009];typedef pair<int, int> P; int main(){ int k; scanf("%d", &k); deque<P> q; memset(vis, 0, sizeof(vis)); q.push_back(make_pair(1, 1)); while(!q.empty()) { P x = q.front(); q.pop_front(); if(vis[x.first]) continue; vis[x.first] = 1; if(x.first == 0) { printf("%d\n", x.second); break; } q.push_front(make_pair(x.first*10 % k, x.second)); q.push_back(make_pair((x.first+1) % k, x.second+1)); } return 0;}
阅读全文
0 0
- Atcoder arc 084 D
- Atcoder ARC 077 D
- [DP]Atcoder ARC 087 D
- Atcoder arc 084 C
- Atcoder ARC 71D 井井井 / ### 公式化简
- atcoder AtCoder Regular Contest 084 D
- Atcoder D
- Atcoder ARC 077 C
- Atcoder ARC 077 E
- Atcoder ARC 077 F
- atcoder 055D D
- atcoder square869120Contest #4 D
- Atcoder 2334 D
- AtCoder-RC078 D
- AtCoder 079D Decrease
- atcoder-abc-070D
- atcoder 062D
- [atcoder] agc86 D
- Java学习 其他笔记
- 接口练习:大学里的学生(Student)需要交学费,而研究生(Graduate)作为学生比较特殊,除了需要交学费外,还可以获取一部分科研津贴,由学校(University)统一发放。此外,学校还需要发
- P2985 [USACO10FEB]吃巧克力
- Python高级编程--如何实现可迭代对象和迭代器对象?(未完待续)
- Qt下使用DbgHelp和SetUnhandledExceptionFilter来获取Crash log/dump文件
- Atcoder arc 084 D
- centOs7 忘记root密码
- 如何删除strut2校验后<s:fielderror>在jsp页面输出时的小黑点和自动换行?
- 自我总结的HTML
- TankWar游戏(图片版)----阶段四
- [leetcode]312. Burst Balloons
- [Oracle 11g r2(11.2.0.4.0)]Oracle Golden Gate Training-workshop5
- Python高级编程-如何实现反向迭代?
- jquery html标签替换