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]
4 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]4 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
How can we calculate the speed of the output gear in a simple gear train? Explain with the help of an example.
Snowcat [4.5K]

Answer:

N_3=\dfrac{T_1}{T_3}N_1

Explanation:

In the diagram there three gears in which gear 1 is input gear ,gear 2 is idle gear and gear 3 is out put gear.

Lets take

Speed\ of\ gear 1=N_1

Number\ of\ teeth\ of\ gear 1=T_1

Speed\ of\ gear 3=N_3

Number\ of\ teeth\ of\ gear 3=T_3

All external matting gears will rotates in opposite direction with respect to each other.

So the speed of gear third can be given as follows

\dfrac{T_1}{T_3}=\dfrac{N_3}{N_1}

N_3=\dfrac{T_1}{T_3}N_1

3 0
3 years ago
Answer the following either true (T) or false (F) (5 pts)
likoan [24]

Answer:

1. True

2. True

3. False

Explanation:

The office location is where the soil layer is not uniform. The thickness of the soil varies which could lead to doors being jammed. The engineer needs to estimate the differential in clay soil.

The inclined surface can hold less weight than a vertical surface. The capacity to hold the weight is due to the gravitational force which is exerted to the load.

6 0
3 years ago
Sketch T-s and p-v diagrams for the Diesel cycle.
labwork [276]

Answer:

Diesel cycle:

    All diesel engine works on diesel cycle.It have four processes .These four processes are as follows

1-2.Reversible adiabatic compression

2-3.Heat addition at constant pressure

3-4.Reversible adiabatic expansion

4-1.Heat addition at constant volume

When air inters in the piston cylinder after that it compresses and gets heated due to compression after that heat addition take place at constant pressure after that power is produces when piston moves to bottom dead center.

From the diagram of P-v And T-s we can understand so easily.

3 0
3 years ago
A reversible power cycle R and an irreversible power cycle I operate between the same hot and cold thermal reservoirs. Cycle I h
anygoal [31]

Answer: Attached below is the missing diagram

answer :

A)   1) Wr > WI,     2) Qc' > Qc

B)   1) QH' > QH,   2) Qc' > Qc

Explanation:

  л = w / QH = 1 - Qc / QH  and  QH = w + Qc

<u>A) each cycle receives same amount of energy by heat transfer</u>

<u>(</u> Given that ; Л1 = 1/3 ЛR )

<em>1) develops greater bet work </em>

WR develops greater work ( i.e. Wr > WI )

<em>2) discharges greater energy by heat transfer</em>

 Qc' > Qc

solution attached below

<u>B) If Each cycle develops the same net work </u>

<em>1) Receives greater net energy by heat transfer from hot reservoir</em>

QH' > QH   ( solution is attached below )

<em>2) discharges greater energy  by heat transfer to the cold reservoir</em>

Qc' > Qc

solution attached below

4 0
3 years ago
Design process 8 steps with definition​
Troyanec [42]

Answer:

Step 1: Define the Problem.  

Step 2: Do Background Research. .

Step 3: Specify Requirements. .

Step 4: Brainstorm, Evaluate and Choose Solution.  

Step 5: Develop and Prototype Solution.  

Step 6: Test Solution.

Step 7: Does Your Solution Meet the Requirements?  

Step 8: Communicate Results.

can u tell me the definition tho?

palled correctly as “though” which is an alternate form of “although”) at the end is informal usage. It's better placed before “she seems better today

8 0
3 years ago
Other questions:
  • The driveshaft of an automobile is being designed to transmit 238 hp at 3710 rpm. Determine the minimum diameter d required for
    8·1 answer
  • Discuss the impact of the changing urban center. Include the impacts on political, economic, and social roles and opportunities.
    12·1 answer
  • Part A - Transmitted power A solid circular rod is used to transmit power from a motor to a machine. The diameter of the rod is
    8·1 answer
  • Air at 7 deg Celcius enters a turbojet engine at a rate of 16 kg/s and at a velocity of 300 m/s (relative to engine). Air is hea
    7·1 answer
  • A pool of contaminated water is lined with a 40 cm thick containment barrier. The contaminant in the pit has a concentration of
    11·1 answer
  • Assume a steel pipe of inner radius r1= 20 mm and outer radius r2= 25 mm, which is exposed to natural convection at h = 50 W/m2.
    12·1 answer
  • -Electronic control modules can easily evaluate the voltage and current levels of circuits to which they are connected and deter
    15·1 answer
  • calculate force and moment reactions at bolted base O of overhead traffic signal assembly. each traffic signal has a mass 36kg,
    6·1 answer
  • Please help I am give brainiliest
    9·1 answer
  • The corner store sells candy in ₵20, ₵30 and ₵50 packages. List all the ways in which the Candyman
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!