麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

poj--3278Catch That Cow(搜索)

2019-11-06 08:16:27
字體:
來源:轉載
供稿:網友

Catch That Cow

Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 84880 Accepted: 26651點擊打開鏈接DescriptionFarmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleporting.* Walking: FJ can move from any point X to the points X - 1 or X + 1 in a single minute* Teleporting: FJ can move from any point X to the point 2 × X in a single minute.If the cow, unaware of its pursuit, does not move at all, how long does it take for Farmer John to retrieve it?InputLine 1: Two space-separated integers: N and KOutputLine 1: The least amount of time, in minutes, it takes for Farmer John to catch the fugitive cow.Sample Input5 17Sample Output4HintThe fastest way for Farmer John to reach the fugitive cow is to move along the following path: 5-10-9-18-17, which takes 4 minutes.Source

USACO 2007 Open Silver

題意:這道題的意思是:在一條線上有兩個點n,k;其中從n點往前走(即k點走),有兩種方法:

1、走一步距離1m(可以往前,可以往后),一秒

2、走2*1m(可以往前,可以往后),一秒

問:花費時間最少。

#include<iostream>#include<cstring>#include<queue>#include<cstdio>using namespace std;const int N=1000000;int map[N+10];int n,k;struct node{int x,step;};int check(int x){    if(x<0||x>=N||map[x])        return 0;    return 1;}int bfs(int x){    int i;    queue<node>Q;    node a,next;    a.x=x;    a.step=0;    map[x]=1;    Q.push(a);    while(!Q.empty())    {        a=Q.front();        Q.pop();        if(a.x==k)            return a.step;        next=a;        next.x=a.x+1;        if(check(next.x))        {            next.step=a.step+1;            map[next.x]=1;            Q.push(next);        }        next.x=a.x-1;        if(check(next.x))        {            next.step=a.step+1;            map[next.x]=1;            Q.push(next);        }        next.x=a.x*2;        if(check(next.x))        {            next.step=a.step+1;            map[next.x]=1;            Q.push(next);        }    }    return -1;}int main(){    int ans;    while(scanf("%d%d",&n,&k)!=EOF)    {        memset(map,0,sizeof(map));        ans=bfs(n);        PRintf("%d/n",ans);    }    return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲精品成人18久久久久 | 91重口视频 | 日韩精品一区二 | 特一级黄色毛片 | 国产九色视频在线观看 | av在线播放亚洲 | 禁漫天堂久久久久久久久久 | 欧美成人精品一级 | 欧美一级特黄aaaaaaa什 | 久久久久久久久久久久久九 | 久久第四色 | 素人视频在线观看免费 | 黄色大片网站在线观看 | 色网免费观看 | 中国老女人一级毛片视频 | 日本欧美一区二区三区视频麻豆 | 国产老师做www爽爽爽视频 | 久久视频精品 | 黄色毛片观看 | 一级免费特黄视频 | 中文字幕观看 | 一级免费| 一级片免费在线 | 久久久久99一区二区三区 | 久久av免费 | 黄色大片在线免费观看 | 久久国产精品一区 | 亚洲午夜一区二区三区 | 一级黄色免费观看 | av免费在线观看国产 | 欧美成年人视频 | 久久久午夜电影 | 欧美爱爱视频免费看 | 色吧综合网 | 亚洲国产精品久久久久久久 | www嫩草| 欧美一级特黄aaaaaa在线看首页 | 午夜视频在线免费观看 | 国产成人精品免费视频大全最热 | 免费男女视频 | av最新在线观看 |