AtCoder Regular Contest 084 (upc 6616) Small Multiple

22 篇文章 0 订阅
9 篇文章 0 订阅

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

题目:找一个k的倍数而且这个数的所有数的和是他的倍数里面的最小的。

思维:就是你XJB想想对于一个数来说,你可以考虑0-K-1最为一个数的开头,如果是选择K开头的话而且他是一个数的倍数的话,那么你肯定可以缩减成0开头的一个数同理k+1可以变成1 这样XJB乱想,就变成了0 - k-1开头的数通过+1 *102各种操作来求最小的一个位数和。(我不知道为啥跟SB一样纠结10%p 跟100%p为啥不相等)。然后就bfs贪心呗,最后别忘了1是从0过来的所以需要+1.

#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n,cnt; 
struct node{
    int u;
    int v;
    int valu;
    int next;
}no[1000005];
int dist[100005];
int head[100005];
void add(int u,int v,int valu)
{
    no[cnt].u=u;
    no[cnt].v=v;
    no[cnt].valu=valu;
    no[cnt].next=head[u];
    head[u]=cnt++;
}
void bfs()
{
    memset(dist,INF,sizeof(dist));
    dist[1]=0;
    queue<int>q;
    q.push(1);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=head[u];i!=-1;i=no[i].next)
        {
            int v=no[i].v;
            if(dist[v] > dist[u] + no[i].valu)
            {
                dist[v]=dist[u] + no[i].valu;
                q.push(v);
            }
        }
    }
    dist[0]=dist[0]+1;//0 - 1 需要加 1  
    printf("%d\n",dist[0]);
}
int main()
{
    memset(head,-1,sizeof(head));
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        add(i,(i+1)%n,1);//+1
        add(i,(i*10)%n,0);//乘以10 
    }
    bfs();
    return 0; 
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值