2016年第六届蓝桥杯C/C++程序设计本科B组决赛 ——一步之遥(填空题题)


一步之遥

从昏迷中醒来,小明发现自己被关在X星球的废矿车里。矿车停在平直的废弃的轨道上。
他的面前是两个按钮,分别写着“F”和“B”。

小明突然记起来,这两个按钮可以控制矿车在轨道上前进和后退。
按F,会前进97米。按B会后退127米。
透过昏暗的灯光,小明看到自己前方1米远正好有个监控探头。
他必须设法使得矿车正好停在摄像头的下方,才有机会争取同伴的援助。
或许,通过多次操作F和B可以办到。

矿车上的动力已经不太足,黄色的警示灯在默默闪烁...
每次进行 F 或 B 操作都会消耗一定的能量。
小明飞快地计算,至少要多少次操作,才能把矿车准确地停在前方1米远
的地方。

请填写为了达成目标,最少需要操作的次数。

注意,需要提交的是一个整数,不要填写任何无关内容(比如:解释说明
等)


思路:看着很像是搜索bfs,还记得一个农场主去抓一头牛的题目吧!BFS来一发!

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<string.h>
 4 #include<vector>
 5 #include<math.h>
 6 #include<algorithm>
 7 #include<set>
 8 #include<string.h>
 9 #include<string>
10 #include<map>
11 #include<queue>
12 using namespace std;
13 #define N 100008
14 #define ll long long
15 #define ull unsigned long long
16 #define inf 0x3f3f3f3f
17 struct node{
18     int x,step;
19     node(int x=0,int step=0):x(x),step(step){}
20 };
21 
22 
23 int main(){
24     int a,b;
25     for(int a=1;a<=100;a++){
26         for(int b=1;b<=1000;b++){
27             int s=a*97+b*(-127);
28             if(s<-100)
29                 continue;
30             if(s==1){
31                 printf("%d %d\n",a,b);
32                 return 0;
33             }
34         }
35     }
36 
37 
38     return 0;
39 }
View Code

猜你喜欢

转载自www.cnblogs.com/zhazhaacmer/p/9020676.html