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
(a)Compute the electrical conductivity of a cylindrical silicon specimen 7.0 mm (0.28 in.) diameter and 57 mm (2.25 in.) in leng
igor_vitrenko [27]

Answer:

a) \sigma = 12.2 (Ω-m)^{-1}

b) Resistance = 121.4 Ω

Explanation:

given data:

diameter is 7.0 mm

length 57 mm

current I = 0.25 A

voltage v = 24 v

distance between the probes is 45 mm

electrical conductivity is given as

\sigma = \frac{I l}{V \pi r^2}

\sigma  = \frac{0.25 \times 45\times 10^{-3}}{24 \pi [\frac{7 \times 10^{-3}}{2}]^2}

\sigma = 12.2(Ω-m)^{-1}[/tex]

b)

Resistance = \frac{l}{\sigma A}

                  = \frac{l}{ \sigma \pi r^2}

= \frac{57  \times 10^{-3}}{12.2 \times \pi [\frac{7 \times 10^{-3}}{2}]^2}

Resistance = 121.4 Ω

8 0
3 years ago
Voltage-regulated channels can be found a. at the motor end plate. b. on the surfaces of dendrites. c. in the membrane that cove
USPshnik [31]

Answer:

Option C

In the membrane that covers axons

Explanation:

Voltage-regulated channels allow for selective passage of different beneficial ions such as potassium and are  found on the surface of a wide variety of cells such as nerve, muscle, and secretory cells. They mainly regulate cell membrane excitability, repetitive low frequency firing in some neurons, and recover the nerve fiber membrane.

7 0
3 years ago
A weight-lifting athlete raises a mass of 160 kg through a vertical distance of 1.4 m. What force did
Over [174]

Answer:

1568N

2195.2J

Explanation:

Given parameters:

Mass of the weight = 160kg

Distance  = 1.4m

Unknown:

Force applied to lift the weight = ?

Energy expended  = ?

Solution:

The force applied in moving a body with a given mass through a distance is the weight;

     Force applied  = mg

Where m is the mass

           g is the acceleration due to gravity

i.  Applied force = 160 x 9.8  = 1568N

ii. The energy used to lift the weight is given as;

     Energy  = mgh

h is the vertical distance

     Energy  = 1568 x 1.4  = 2195.2J

8 0
3 years ago
Kieran and Kurt spend most of their day performing physical labor, aligning materials, and inspecting projects for quality and s
xxMikexx [17]

Answer:

Kieran is a Carpenter, and Kurt is a Drafter

Explanation:

Among all the professions listed, Kurt can only possibly be a Drafter.  A Drafter is an engineering technician who makes detailed technical drawings or plans for machinery, buildings, electronics, infrastructure, sections, etc. Drafters make use of computer software and manual sketches to convert the designs, plans, and layouts of engineers and architects into a set of technical drawings. All the other professions will at some point need for the professional to stand and work at an height above the ground except for a drafter, whose feet will remain on the ground at almost all times.

5 0
3 years ago
Read 2 more answers
Design a 8th order wideband band-pass Butterworth filter with a lower cutoff frequency of 45 Hz, an upper cutoff frequency of 17
Lunna [17]

Explanation:

71hz 45+17+9

5 0
2 years ago
Other questions:
  • Steam enters a radiator at 16 psia and 0.97 quality. The steam flows through the radiator, is con- densed, and leaves as liquid
    15·1 answer
  • Three return steam lines in a chemical processing plant enter a collection tank operating at steady state at 1 bar. Steam enters
    6·1 answer
  • Which of the following best describes the role of engineers
    12·1 answer
  • In the given circuit, V(t)=12cos(2000t+45)V, R1=R2=2Ω, L1=L2=L3=3mH and C1=250μF. You are required to find the Thevenin equivale
    7·1 answer
  • The steel framework is used to support the reinforced stone concrete slab that is used for an office. The slab is 200 mm thick.
    8·1 answer
  • A model shows a city located between a warm ocean and next to coastal mountains. Which statement best describes average weather
    8·2 answers
  • 2. How many amperes of current will flow through a circuit that has 3 ohms of resistance if
    5·1 answer
  • The marginal rate of substitution is the slope of the indifference curve.
    6·1 answer
  • 10. True or False? A disruptive technology<br> radically changes the way people live and<br> work.
    5·2 answers
  • Blank is an art form in which the focus is to make life and society better
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!