# Small Multiple（最短路）

### 6616: Small Multiple

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 is given from Standard Input in the following format:
K

Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K.

6

3

12=6×2 yields the smallest sum.

1、x与x+1建边，边权为1，因为各个位数之和相比与x加了1。x+1要%k。

2、x与x*10建边，边权为0，各个位数和不变。x*10%k。

3、跑最短路。

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e6+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
struct node
{
int from, to, w;
} G[MAX];
int dist[MAX];
bool vis[MAX];
int cnt;
void add(int u, int v, int w)
{
G[cnt].to=v;
G[cnt].w=w;
}
int k;
void init()
{
int i,j;
memset(vis,0,sizeof(vis));
fill(dist,dist+MAX,100000);

scanf("%d",&k);
for(i=0;i<k;i++)
{
int a=i;
int b=(i+1)%k;
int c=i*10%k;

}
}

void spfa(int s)
{
memset(vis, false, sizeof(vis));
queue<int> q;
while(!q.empty())
q.pop();
vis[1]=true;
q.push(s);
dist[s]=0;
while(!q.empty())
{
int u=q.front();
q.pop();
vis[u]=false;
{
int v=G[i].to;
if(dist[v]>dist[u]+G[i].w)
{
dist[v]=dist[u]+G[i].w;
if(!vis[v])
{
vis[v]=true;
q.push(v);
}
}
}
}
}

void output()
{
printf("%d\n",dist[0]+1);
}
int main()
{
init();
spfa(1);
output();

return 0;
}



• 点赞
• 评论 3
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 打赏

打赏

七月初七小柠七

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 举报
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文

09-25 211
08-04 244
08-08 70
08-04 110
11-18 290
08-03 185
11-05 725
08-04 200