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;
    }
    
    
  • 相关阅读:
    VIJOS-P1340 拯救ice-cream(广搜+优先级队列)
    uva 11754 Code Feat
    uva11426 GCD Extreme(II)
    uvalive 4119 Always an Interger
    POJ 1442 Black Box 优先队列
    2014上海网络赛 HDU 5053 the Sum of Cube
    uvalive 4795 Paperweight
    uvalive 4589 Asteroids
    uvalive 4973 Ardenia
    DP——数字游戏
  • 原文地址:https://www.cnblogs.com/Hxymmm/p/7784910.html
Copyright © 2011-2022 走看看