1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
trapecia [35]
3 years ago
14

Your program should read from an input file, which will contain one or more test cases. Each test case consists of one line cont

aining two squares separated by one space. A square is a string consisting of a letter (a-h) representing the column and a digit (1-8) representing the row on the chessboard.
Engineering
1 answer:
Aliun [14]3 years ago
3 0

Answer:

#include <bits/stdc++.h>

using namespace std;

struct cell

{

int x, y;

int dis;

cell() {}

cell(int x, int y, int dis) : x(x), y(y), dis(dis) {}

};

bool isInside(int x, int y, int N)

{

if (x >= 1 && x <= N && y >= 1 && y <= N)

return true;

return false;

}

int minStepToReachTarget(int knightPos[], int targetPos[],

int N)

{

int dx[] = {-2, -1, 1, 2, -2, -1, 1, 2};

int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};

queue<cell> q;

q.push(cell(knightPos[0], knightPos[1], 0));

cell t;

int x, y;

bool visit[N + 1][N + 1];

for (int i = 1; i <= N; i++)

for (int j = 1; j <= N; j++)

visit[i][j] = false;

visit[knightPos[0]][knightPos[1]] = true;

while (!q.empty())

{

t = q.front();

q.pop();

visit[t.x][t.y] = true;

if (t.x == targetPos[0] && t.y == targetPos[1])

return t.dis;

for (int i = 0; i < 8; i++)

{

x = t.x + dx[i];

y = t.y + dy[i];

if (isInside(x, y, N) && !visit[x][y])

q.push(cell(x, y, t.dis + 1));

}

}

}

int main(){

ifstream obj("input.txt");

string line;

int x1,y1,x2,y2;

while(getline(obj,line)){

//cout<<line<<endl;

x1=line[0]-'a'+1;

y1=line[1]-'0';

x2=line[3]-'a'+1;

y2=line[4]-'0';

int N = 8;

int knightPos[] = {x1,y1};

int targetPos[] = {x2,y2};

cout <<"To get from "<<line[0]<<line[1]<<" to "<<line[3]<<line[4]<<" takes "<< minStepToReachTarget(knightPos, targetPos, N)<<" Knight Moves."<<endl;

}

return 0;

}

You might be interested in
Write down the types and tasks of the pressure control valves ?
Yuki888 [10]

Answer:

There are 6 types of pressure control valves and their function is to regulate the pressure below a threshold level within safe limits and to maintain and control  pressure of a particular circuit.

Explanation:

The six type of Pressure valve with their functions are given below:

a. Unloading Valve:

These type of pressure valve are used to pour fluid into the container at very low or no pressure.

b. Safety valve:

These are used when the pressure within the vessel is in excess as inside temperature is near about preset [point point then these valves are open to release the extra pressure and are closed once normal conditions are regained.

c. Pressure Reducing Valve:

These are basically used for the control of the pressure in downstream not exceeding the design limits.

d. Pressure Relief Valves:

These are basically used to limit and regulate the pressure of any system.

e. Counter Balance Valve:

These are used to develop pressure in the reverse direction at the actuator's return line in order to keep the load under control.

f. Sequence Valve:

These are used to maintain sequence or order in the operations of two parts or branches.

8 0
3 years ago
Drag each tile to the correct box.
Trava [24]

Answer:

Bluray

DVD

CD

Explanation:

Blu ray can hold 25gb per layer

Dvd can hold 4.7GB on a single layer

Cd can hold around 737 mb

Also, dvds can go up to 2 layers

Blu ray can go up to 4

6 0
3 years ago
If it is desired to lay off a distance of 10,000' with a total error of no more than ± 0.30 ft. If a 100' tape is used and the
Ira Lisetskai [31]

Answer:

± 0.003 ft

Explanation:

Since our distance is 10,000 ft and we need to use a full tape measure of 100 ft. We find that 10,000 = 100 × 100.

Let L' = our distance and L = our tape measure

So, L' = 100L

Now by error determination ΔL' = 100ΔL

Now ΔL' = ± 0.30 ft

ΔL = ΔL'/100

= ± 0.30 ft/100

= ± 0.003 ft

So, the maxim error per tape is ± 0.003 ft

3 0
3 years ago
Express 2/16 in thirty-seconds
mafiozo [28]

Answer:

\frac{2}{16}  = \frac{4}{32} in thirty seconds.

Explanation:

one thirty second is one part out of 32 equal section . It is used to describe amounts accurately.

\frac{2}{16} can be easily expressed as \frac{4}{32}

3 0
2 years ago
What Advantage does a voltmeter have over a noncontact voltage indicator when testing for voltage
galina1969 [7]

Answer:

Obviously you shouldn't rely just on the meter for your safety. You'd disconnect wall fuses or kill main switches before you start, using the meter just gives you some extra protection: with the meter you might notice for example that you've disconnected the wrong fuse and the unit is still live.

Explanation:

Hope it helps! :)

5 0
2 years ago
Other questions:
  • The uniform dresser has a weight of 90 lb and rests on a tile floor for which the coefficient of static friction is 0.25. If the
    6·1 answer
  • A wastewater treatment plant has two primary clarifiers, each 20m in diameter with a 2-m side-water depth. the effluent weirs ar
    8·1 answer
  • Q1. In electronic circuits it is not unusual to encounter currents in the microampere range. Assume a 35 μA current, due to the
    13·1 answer
  • A 220-V electric heater has two heating coils that can be switched such that either coil can be used independently or the two ca
    15·1 answer
  • For laminar flow of air over a flat plate that has a uniform surface temperature, the curve that most closely describes the vari
    15·1 answer
  • In a CNC machining operation, the has to be moved from point (5, 4) to point(7, 2)along a circular path with center at (7,2). Be
    5·1 answer
  • Which sentence is correct about the exergy of an empty (pressure around zero Pascal) tank with a volume of V, located in an envi
    7·1 answer
  • You are using a Jupyter Notebook to explore data in a DataFrame named productDF. You want to write some inline SQL by using the
    8·1 answer
  • A furnace uses preheated air to improve its fuel efficiency. Determine the adiabatic flame temperature when the furnance is oper
    13·1 answer
  • A school bus with its flashing red signals on has stopped on a non-divided highway; you must?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!