题意:更改四位数的门牌号(素数),每次只能改一个数字,问最少多少次能改到目标数字。
思路:打表出四位的所有素数,然后建图,只有一个位数的数字不同的连边,跑最短路,,,
#include<iostream>
#include<stdio.h>
#include<queue>
#include<string.h>
const int N=10000;
const int inf=0x3fffffff;
using namespace std;
int link[N],prim[N],dis[N],vis[N];
struct edge
{
int st,ed,next;
}e[N*10];
int head[N],num;
void addedge(int x,int y)
{
e[num].st=x;e[num].ed=y;e[num].next=hea......
阅读全文