zoukankan      html  css  js  c++  java
  • AtCoder Regular Contest 084 D

    Problem Statement

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

    translation

    求出一个K的倍数使得每一个位置上数的和最小

    solution

    正解:搜索
    需要设计一个巧妙的状态,我们选择搜索相乘的结果 (p),二元组 ((x,y)),表示 p%k=x,每一个位置上相加为 (y) 这个状态,然后枚举每一位转移即可.当结果 $ p$ 能够整除 (k) 时更新答案,关键要意识到答案不超过 (45),所以状态数 (O(K*45)),可以搜过

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #define RG register
    #define il inline
    #define iter iterator
    #define Max(a,b) ((a)>(b)?(a):(b))
    #define Min(a,b) ((a)<(b)?(a):(b))
    using namespace std;
    const int LIM=47,N=1e5+5;
    bool vis[N][LIM];int k,q[N*LIM][2];
    void work()
    {
       scanf("%d",&k);
       int t=0,sum=0,x,u;
       for(int i=1;i<=9;i++){
          q[++sum][0]=i%k;
          q[sum][1]=i;
          vis[i%k][i]=1;
       }
       int tx,tu,ans=1e5;
       while(t!=sum){
          t++;x=q[t][0];u=q[t][1];
          if(x==0)ans=Min(ans,u);
          for(int i=0;i<=9;i++){
             tx=(x*10+i)%k;
             tu=u+i;
             if(tu>=LIM)continue;
             if(!vis[tx][tu]){
                vis[tx][tu]=1;
                q[++sum][0]=tx;
                q[sum][1]=tu;
             }
          }
       }
       printf("%d
    ",ans);
    }
    
    int main()
    {
    	work();
    	return 0;
    }
    
    
  • 相关阅读:
    k8s之StatefulSet介绍(六)
    k8s之Deployment 声明式地升级应用(五)
    k8s 挂载卷介绍(四)
    k8s 之service资源介绍(三)
    k8s几种pod的控制器
    k8s 初识pod (二)
    k8s的常用命令(一)
    k8s 学习笔记
    aws centos系统磁盘扩容
    mac更改launchpad图标大小
  • 原文地址:https://www.cnblogs.com/Hxymmm/p/7784910.html
Copyright © 2011-2022 走看看