hdu 4294 Multiple BFS

本文介绍了一道算法题的解决方法,该题要求找到一个正整数N的最小整数倍M,使得M在K进制表示下包含最少的不同数字,并详细解释了解题思路及实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Multiple

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 954    Accepted Submission(s): 230


Problem Description
  Given a positive integer N, you’re to solve the following problem:
  Find a positive multiple of N, says M, that contains minimal number of different digits in base-K notation. If there’re several solutions, you should output the numerical smallest one. By saying numerical smallest one, we compar their numerical value, so 0xA hex < 11 dec.
  You may assume that 1 <= N <= 10 4 and 2 <= K <= 10.
 

Input
  There’re several (less than 50) test cases, one case per line.
  For each test case, there is a line with two integers separated by a single space, N and K.
  Please process until EOF (End Of File).
 

Output
  For each test case, you should print a single integer one line, representing M in base-K notation,the answer.
 

Sample Input
  
10 8 2 3 7 5
 

Sample Output
  
2222 2 111111
 

Source

题目大意:求N的最小整数倍在k进制下不同的数字的个数是最小的那个倍数

解题思路:对于a,aa,aaa,....,aaa..aa这n个数字的情况,如果有一个mod n为0,那么最小的数字个数为1,否则,在这n个数字中,必然存在2个数mod n是同余的,所以必然存在2个的差值aaaa000这种形式的数mod n为0,所以答案最多只会有两个数字。

对于一个数字的情况,直接暴力即可,对于两个的情况,枚举2个数字,用bfs模拟2个数字的排列,注意要以和mod n的值作为状态,这同一个mod n的值对应一个值最小的答案。


<span style="font-size:18px;">#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
int n,k;
struct node{
    int mod,w,x;
    node(){}
    node(int mod,int w,int x):mod(mod),w(w),x(x){}
}now;
string ret;
int pre[10010];
int s[10010];
bool vis[10010];
void bfs(){
    for(int i=1;i<k;i++){
        for(int j=0;j<i;j++){
            int ans=-1;
            queue<node> q;
            int z=0;
            memset(vis,0,sizeof vis);
            q.push(node(i,1,z));
            pre[0]=-1,s[0]=i,z++;
            vis[i]=1;
            if(j) q.push(node(j,1,z));
            pre[1]=-1,s[1]=j,z++;
            while(!q.empty()){
                now=q.front();
                q.pop();
                if(now.mod==0){
                    ans=now.x;
                    break;
                }
                if(!vis[(now.mod*k+j)%n]){
                    vis[(now.mod*k+j)%n]=1;
                    pre[z]=now.x;
                    s[z]=j;
                    q.push(node((now.mod*k+j)%n,now.w+1,z));
                    z++;
                }
                if(!vis[(now.mod*k+i)%n]){
                    vis[(now.mod*k+i)%n]=1;
                    pre[z]=now.x;
                    s[z]=i;
                    q.push(node((now.mod*k+i)%n,now.w+1,z));
                    z++;
                }
            }
            if(ans==-1) continue;
            string ss="";
            for(int i=ans;i!=-1;i=pre[i]){
                ss.push_back(s[i]+'0');
            }
            int l=ss.size();
            for(int i=0;i<l/2;i++) swap(ss[i],ss[l-1-i]);
            if(ss.size()<ret.size()){
                ret=ss;
            }else if(ss.size()==ret.size()){
                if(ss<ret){
                    ret=ss;
                }
            }
        }
    }
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d%d",&n,&k))
    {
        ret="";
        for(int i=0;i<=n;i++) ret.push_back('9');
        string tmp;
        int mod;
        bool flag=0;
        for(int i=1;i<k;i++){
            tmp="";
            mod=0;
            for(int j=0;j<n;j++){
                tmp.push_back('0'+i);
                mod=(mod*k+i)%n;
                if(mod==0){
                    if(tmp.size()<ret.size()){
                        ret=tmp;
                        flag=1;
                    }else if(tmp.size()==ret.size()){
                        if(tmp<ret) ret=tmp,flag=1;
                    }
                    break;
                }
            }
        }
        if(!flag) bfs();
        printf("%s\n",ret.c_str());
    }
    return 0;
}
</span>

内容概要:该论文聚焦于T2WI核磁共振图像超分辨率问题,提出了一种利用T1WI模态作为辅助信息的跨模态解决方案。其主要贡献包括:提出基于高频信息约束的网络框架,通过主干特征提取分支和高频结构先验建模分支结合Transformer模块和注意力机制有效重建高频细节;设计渐进式特征匹配融合框架,采用多阶段相似特征匹配算法提高匹配鲁棒性;引入模型量化技术降低推理资源需求。实验结果表明,该方法不仅提高了超分辨率性能,还保持了图像质量。 适合人群:从事医学图像处理、计算机视觉领域的研究人员和工程师,尤其是对核磁共振图像超分辨率感兴趣的学者和技术开发者。 使用场景及目标:①适用于需要提升T2WI核磁共振图像分辨率的应用场景;②目标是通过跨模态信息融合提高图像质量,解决传统单模态方法难以克服的高频细节丢失问题;③为临床诊断提供更高质量的影像资料,帮助医生更准确地识别病灶。 其他说明:论文不仅提供了详细的网络架构设计与实现代码,还深入探讨了跨模态噪声的本质、高频信息约束的实现方式以及渐进式特征匹配的具体过程。此外,作者还对模型进行了量化处理,使得该方法可以在资源受限环境下高效运行。阅读时应重点关注论文中提到的技术创新点及其背后的原理,理解如何通过跨模态信息融合提升图像重建效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值