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
An insulated piston-cylinder device initially contains 0.16 m2 of CO2 at 150 kPa and 41 °C. Electric resistance heater supplied
lyudmila [28]

Answer:

I=0.3636

Explanation:

See the attached picture for explanation.

4 0
3 years ago
State two faults that are common in a simple cell​
Step2247 [10]

Answer:

the two defects of a simple cell are:

1. Polarization

2. Local action

4 0
3 years ago
Read 2 more answers
Identify three operational controls and explain<br> how to use them?
ladessa [460]

Answer:

5.1 Personnel Security. ...

5.2 Physical and Environmental Protection. ...

5.3 Production, Input and Output Controls. ...

5.4 Contingency Planning and Disaster Recovery. ...

5.5 System Configuration Management Controls. ...

5.6 Data Integrity / Validation Controls. ...

5.7 Documentation. ...

5.8 Security Awareness and Training.

8 0
3 years ago
Race car is accelerating and has a velocity of 10 m/s @ t=0. It completes a lap on a circular track of 400 m in 14 seconds. Calc
wariber [46]

Answer:

component of acceleration are a = 3.37 m/s² and ar = 22.74 m/s²

magnitude of acceleration is  22.98 m/s²

Explanation:

given data

velocity = 10 m/s

initial time to = 0

distance s = 400 m

time t = 14 s

to find out

components and magnitude of acceleration after the car has travelled 200 m

solution

first we find the radius of circular track that is

we know  distance S = 2πR

400 = 2πR

R = 63.66 m

and tangential acceleration is

S = ut + 0.5 ×at²

here u is initial speed and t is time and S is distance

400 = 10 × 14  + 0.5 ×a (14)²

a = 3.37 m/s²

and here tangential acceleration is constant

so  velocity at distance 200 m

v² - u² = 2 a S

v² = 10² + 2 ( 3.37) 200

v = 38.05 m/s

so radial acceleration at distance 200 m

ar = \frac{v^2}{R}

ar = \frac{38.05^2}{63.66}

ar = 22.74 m/s²

so magnitude of total acceleration is

A = \sqrt{a^2 + ar^2}

A = \sqrt{3.37^2 + 22.74^2}

A = 22.98 m/s²

so magnitude of acceleration is  22.98 m/s²

8 0
3 years ago
The output voltage of a power supply is normally distributed with mean 12 V and standard deviation 0.11 V. If the upper and lowe
podryga [215]

Answer:

82.62%

Explanation:

The z score is a score used in statistics to determine by how many standard deviations the raw score is above or below the mean. The z score is given by:

z=\frac{x-\mu}{\sigma} \\\\where\ x=raw\ score,\mu=mean\ and\ \sigma=standard\ deviation.\\\\Given \ that\ \mu=12V, \sigma=0.11V.\\\\For\ x11.85V:\\\\z=\frac{11.85-12}{0.11} =-1.36\\\\

From the normal distribution table, P(11.85 < x < 12.15) = P(-1.36 < z < 1.36) = P(z < 1.36) - P(z < -1.36) = 0.9131-0.0869 = 0.8262 = 82.62%

4 0
3 years ago
Other questions:
  • Suppose that a wing component on an aircraft is fabricated from an aluminum alloy that has a plane strain fracture toughness of
    13·1 answer
  • In RSA Digital Signature, Suppose Bob wants to send a signed message (x = 4) to Alice. The first steps are exactly t eps are exa
    5·1 answer
  • 2. In the above figure, what type of cylinder arrangement is shown in the figure above?
    9·2 answers
  • Here, we want to become proficient at changing units so that we can perform calculations as needed. The basic heat transfer equa
    15·1 answer
  • Suppose that the time (in hours) required to repair a machine is an exponentially distributed random variable with parameter ???
    13·1 answer
  • B)<br>State the essential difference between a plain carbon steel<br>and an alloy steel​
    15·1 answer
  • The cost of hiring new employees outpaces the raises for established employees is
    5·1 answer
  • The "Big Dig" was the nickname of the civil engineering project that redesigned the highway Infrastructure for the city of
    7·1 answer
  • Can someone please help!
    8·1 answer
  • Which type of line is represented by thin, short dashes?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!