青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 195,  comments - 30,  trackbacks - 0
#include<iostream>
#include
<queue>
#include
<math.h>
using namespace std;
const int MAX=10000;
int visited[10000];
int result[10000];
bool isprimer(int npp)
 {
     
for (int q = 2; q <= sqrt(double(npp)); ++q)
     {
         
if (npp % q == 0)
         {
             
return 0;
         }
     }
     
return 1;
 
 }

int BFS(int start,int end) 
{
    queue
<int> q;
    
if (start == end)
        
return 0;
    q.push(start);
    visited[start]
=1;
    result[start]
=0;
    
while(!q.empty()) 
    {
        
int temp=q.front();
        q.pop();
        
int next,j,k;
        
int num[3];
        
        
for (int i =0;i<4;++i)
            {    
                 num[
0]=temp%10;
                 num[
1]=(temp%100)/10;
                 num[
2]=(temp%1000)/100;
                 num[
3]=temp/1000;   
                 
for(j=0;j<=9;j++)      
               {                       
                 num[i]
=j;
                 next
=num[0]+num[1]*10+num[2]*100+num[3]*1000;
                 
                 
if((next>1000&&visited[next]!=1)&&isprimer(next))
                 {
                     q.push(next);
                     result[next]
=result[temp]+1;
                     visited[next]
=1;                                             
                 }
                 
if(next==end)
                 {
                   
return result[next];           
                 }
              }     
            } 
    }
    
return MAX;
}
int main() {
    
//freopen("s.txt","r",stdin);
    
//freopen("key.txt","w",stdout);
    int n,k,j,m;
    cin
>>j;
    
while(j--)
    {
    memset(visited,
0,sizeof(visited));
    memset(result,
0,sizeof(result));          
    cin
>>n>>k;
    m
=BFS(n,k);
    
if(m!=MAX)          
    cout
<<m<<endl;
    
else
    cout
<<"Impossible"<<endl;
    }
    
return 0;
}

Description

The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices.
— It is a matter of security to change such things every now and then, to keep the enemy in the dark.
— But look, I have chosen my number 1033 for good reasons. I am the Prime minister, you know!
— I know, so therefore your new number 8179 is also a prime. You will just have to paste four new digits over the four old ones on your office door.
— No, it’s not that simple. Suppose that I change the first digit to an 8, then the number will read 8033 which is not a prime!
— I see, being the prime minister you cannot stand having a non-prime number on your door even for a few seconds.
— Correct! So I must invent a scheme for going from 1033 to 8179 by a path of prime numbers where only one digit is changed from one prime to the next prime.

Now, the minister of finance, who had been eavesdropping, intervened.
— No unnecessary expenditure, please! I happen to know that the price of a digit is one pound.
— Hmm, in that case I need a computer program to minimize the cost. You don't know some very cheap software gurus, do you?
— In fact, I do. You see, there is this programming contest going on... Help the prime minister to find the cheapest prime path between any two given four-digit primes! The first digit must be nonzero, of course. Here is a solution in the case above.
1033
1733
3733
3739
3779
8779
8179
The cost of this solution is 6 pounds. Note that the digit 1 which got pasted over in step 2 can not be reused in the last step – a new 1 must be purchased.

Input

One line with a positive number: the number of test cases (at most 100). Then for each test case, one line with two numbers separated by a blank. Both numbers are four-digit primes (without leading zeros).

Output

One line for each case, either with a number stating the minimal cost or containing the word Impossible.

Sample Input

3
1033 8179
1373 8017
1033 1033

Sample Output

6
7
0

代碼完全可以優(yōu)化,比如定義一個結構體可以省掉result數(shù)組!
懶得改了
發(fā)現(xiàn)poj比joj更驚心動魄?。〗洺ompling,結果半天才出現(xiàn)!
posted on 2009-05-13 23:32 luis 閱讀(724) 評論(2)  編輯 收藏 引用 所屬分類: 搜索

FeedBack:
# re: poj 3126 廣搜
2009-06-29 15:18 | 等等等
為什么BFS中定義的k明明沒有用,刪除后答案卻不對了呢?。?!
不懂?。。?!  回復  更多評論
  
# re: poj 3126 廣搜
2009-06-30 10:59 | luis
@等等等
m=BFS(n,k);中的k是有用的,
-----
while(!q.empty())
{
int temp=q.front();
q.pop();
int next,j,k;//這個k沒用,我刪除后提交還是AC了
int num[3];
-----------  回復  更多評論
  
<2025年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

常用鏈接

留言簿(3)

隨筆分類

隨筆檔案

文章分類

文章檔案

友情鏈接

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            黄色在线一区| 嫩草国产精品入口| 国产精品视频大全| 欧美日韩国产色站一区二区三区| 日韩视频在线一区二区三区| 久久免费视频在线观看| 久久精品123| 快射av在线播放一区| 美女日韩欧美| 欧美国产综合视频| 欧美日韩在线亚洲一区蜜芽| 国产精品多人| 激情综合自拍| 亚洲福利视频网| 久久精品综合| 欧美成人有码| 99热这里只有成人精品国产| 亚洲综合欧美| 国产一区二区三区的电影| 欧美性色aⅴ视频一区日韩精品| 欧美天天视频| 国产亚洲精品v| 亚洲伦理网站| 欧美自拍偷拍午夜视频| 欧美va天堂va视频va在线| 亚洲精品在线观| 欧美一区二区播放| 欧美日韩成人在线观看| 国产欧美日韩视频一区二区| 亚洲高清一二三区| 欧美一区二区| 亚洲品质自拍| 香蕉精品999视频一区二区| 亚洲激情视频| 亚洲影院污污.| 欧美黄免费看| 一区免费视频| 亚洲欧美日韩区| 亚洲国产成人在线视频| 午夜精品区一区二区三| 欧美一区日韩一区| 亚洲国产综合在线| 性欧美videos另类喷潮| 欧美日本一区二区视频在线观看| 国产小视频国产精品| 一区二区三区久久网| 久久资源在线| 亚洲欧美成人网| 欧美婷婷久久| 日韩视频不卡中文| 欧美www视频| 久久黄色级2电影| 国产精品一级在线| 欧美午夜在线| 亚洲三级免费| 男人天堂欧美日韩| 久久精品人人做人人爽电影蜜月| 国产精品美女主播| 亚洲一级电影| 国产一区二区三区无遮挡| 亚洲女同精品视频| 亚洲精品无人区| 久久在精品线影院精品国产| 国产亚洲欧美一区在线观看| 欧美一级视频| 亚洲欧美日韩国产成人精品影院| 欧美日韩综合在线免费观看| 亚洲最新视频在线播放| 欧美日韩不卡视频| 亚洲欧美制服中文字幕| 国产精品视频免费观看| 亚洲综合三区| 亚洲一区影音先锋| 国产美女精品免费电影| 国产日韩欧美一区二区三区在线观看 | 亚洲午夜久久久久久尤物| 欧美视频在线看| 久久综合久久久| 久久精品视频播放| 国内精品久久久久影院色| 久久在线免费观看| 久久午夜色播影院免费高清| 亚洲国产精品成人综合色在线婷婷 | 一本色道久久加勒比精品| 亚洲国内精品| 欧美日韩亚洲视频一区| 香蕉视频成人在线观看| 久久久久久一区| 亚洲理论在线| 亚洲欧美另类久久久精品2019| 亚洲视频在线一区观看| 欧美午夜精品久久久久久超碰| 亚洲欧美日本视频在线观看| 亚洲欧美资源在线| 亚洲第一中文字幕在线观看| 亚洲精品日韩激情在线电影| 亚洲福利免费| 亚洲国产婷婷| 欧美性猛交xxxx乱大交退制版 | 久久久xxx| 狼人天天伊人久久| 亚洲免费网址| 久久综合给合久久狠狠狠97色69| 亚洲美女网站| 午夜精品一区二区在线观看| 亚洲激情一区二区| 亚洲女同同性videoxma| 亚洲国产一区二区三区青草影视 | 免费的成人av| 国产精品一区二区你懂的| 亚洲午夜影视影院在线观看| 一区二区免费看| 一区在线免费观看| 亚洲理论在线| 亚洲高清久久网| 136国产福利精品导航网址应用 | 亚洲激情中文1区| 亚洲国产精品t66y| 国产欧美日韩一区二区三区在线观看| 免费欧美在线| 国产视频在线观看一区二区| 亚洲精品视频在线| 亚洲高清毛片| 久久动漫亚洲| 久久精品观看| 国产精品一区二区女厕厕| 99re热精品| 91久久精品一区| 久久影音先锋| 麻豆精品视频在线| 亚洲欧美一区二区原创| 99精品久久| 免费在线成人av| 老司机精品导航| 国产一区二区三区黄视频| 亚洲视频专区在线| 亚洲一区二区少妇| 99精品国产在热久久婷婷| 亚洲一区二区三区中文字幕在线| 99国产精品久久久| 欧美精品成人在线| 亚洲欧洲一区二区三区久久| 亚洲黄色免费| 欧美成人a视频| 欧美韩日一区二区| 亚洲精品女人| 欧美日韩三级在线| 亚洲午夜一区二区三区| 性欧美8khd高清极品| 欧美成人午夜剧场免费观看| 亚洲日本欧美| 一区二区三区日韩| 国产精品va在线播放| 亚洲性视频h| 国产一区日韩一区| 久久狠狠亚洲综合| 欧美freesex交免费视频| 亚洲国产欧美在线人成| 欧美电影打屁股sp| 日韩视频在线一区| 午夜精品久久久久久久99水蜜桃 | 久久久国际精品| 久久亚洲欧美国产精品乐播| 红桃视频一区| 欧美成人a视频| 在线亚洲+欧美+日本专区| 西西人体一区二区| 极品少妇一区二区三区| 欧美国产第一页| 一区二区免费在线播放| 免费人成网站在线观看欧美高清| 欧美成人在线免费观看| 日韩一区二区精品葵司在线| 欧美午夜精品久久久久久孕妇| 久久久www| 亚洲国产乱码最新视频| 欧美午夜精品久久久久久浪潮| 在线精品视频在线观看高清| 久久亚洲不卡| 一级成人国产| 黄网站色欧美视频| 欧美日韩精品在线视频| 欧美性生交xxxxx久久久| 久久久久久久久久久成人| 亚洲精品视频免费| 久久国产精品久久精品国产 | 欧美国产91| 午夜一区二区三区不卡视频| 91久久精品www人人做人人爽| 亚洲欧美中文在线视频| 亚洲区免费影片| 国产一区二区三区四区老人| 欧美精品1区2区| 久久精品一二三| 亚洲一区二区毛片| 亚洲黄色精品| 欧美va亚洲va国产综合| 久久精品99国产精品日本| 国产精品99久久99久久久二8| 久久国产精彩视频|