Atcoder R84 D Small Multiple】的更多相关文章

题意:给定一个正整数K,求K的倍数中,各位上的数字之和最小是多少? 思路非常巧妙,对于一个数,我们有定义两种改变方式: 1.加1,则数字之和+1(9的情况另行考虑) 2.乘10,数字之和不变 对于末位9的情况,我们可以归化为第二种. 于是将x到x+1连一条权值为1的边,x到x*10连一条权值为0的边,最后再模K意义下跑一边1到0的最短路即可 #include<bits/stdc++.h> #include<ext/pb_ds/priority_queue.hpp> using na…
[题意]求一个k的倍数使其数位和最小,输出数位和,k<=10^5. [算法]最短路 [题解]考虑极端情况数字是可能爆long long的(例如k*num=100...000),所以确定基本方向是依次考虑答案x的每个数位. 考虑x初始是1~9,每次在后面加一位,就有x*10+0~9十种操作. 但是x可以无限大,而且x必须是k的倍数这点很难实现,综合这两点可以考虑%k. 进一步发现,%k意义下同余的数字是等价的,也就是%k等于同一个数的x只需要保留数字和最小的. 那么就可以得到算法: k个点表示%k…
水过前三道题之后,一直在写这个题,做不对.总有那么几组数据过不去... 看了看题解是最短路,这思路感觉很神奇.看了下唯一做出来这题的那人的代码,是搜索做的. 标程: 对每个数字x,向x+1建一条花费为1的边,向x * 10建一条花费为0的边,这样1---0的最短路+1就是结果了. 可能有人会疑惑9+1=10,费用确是+1这里,因为1 * 10=10已经向10建立了一条更短的边了,9+1=10那条边就不会走了. 看看代码就懂了. #include <bits/stdc++.h> using na…
A - K-City Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement In K-city, there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each…
A - Infinite Coins 题目链接:https://abc088.contest.atcoder.jp/tasks/abc088_a Time limit : 2sec / Memory limit : 256MB Score: 100 points Problem Statement E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen u…
A - Buying Sweets 题目链接:https://abc087.contest.atcoder.jp/tasks/abc087_a Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one…
A - Already 2018 题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement On some day in January 2018, Takaki is writing a document. The document has a column where the curren…
题目链接:http://abc070.contest.atcoder.jp/assignments A - Palindromic Number Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement You are given a three-digit positive integer N.Determine whether N is a palindromic number.Here, a…
题目链接:http://abc069.contest.atcoder.jp/assignments A - K-City Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement In K-city, there are n streets running east-west, and m streets running north-south. Each street running east-w…
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include<cstdio> using namespace std; #define ll long long #define MAX 100100 inline int read() { int x=0;bool t=false;char ch=getchar(); while((ch<'0'||ch>…