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
Sea water with a density of 1025 kg/m3 flows steadily through a pump at 0.21 m3 /s. The pump inlet is 0.25 m in diameter. At the
myrzilka [38]

Answer:

\dot W_{pump} = 16264.922\,W\,(16.265\,kW)

Explanation:

The pump is modelled after applying Principle of Energy Conservation, whose form is:

\frac{P_{1}}{\rho\cdot g}+ \frac{v_{1}^{2}}{2\cdot g} +z_{1} + h_{pump}=\frac{P_{2}}{\rho\cdot g}+ \frac{v_{2}^{2}}{2\cdot g} +z_{2}

The head associated with the pump is cleared:

h_{pump} = \frac{P_{2}-P_{1}}{\rho\cdot g}+\frac{v_{2}^{2}-v_{1}^{2}}{2\cdot g}+(z_{2}-z_{1})

Inlet and outlet velocities are found:

v_{1} = \frac{0.21\,\frac{m^{3}}{s} }{\frac{\pi}{4}\cdot (0.25\,m)^{2} }

v_{1} \approx 4.278\,\frac{m}{s}

v_{2} = \frac{0.21\,\frac{m^{3}}{s} }{\frac{\pi}{4}\cdot (0.152\,m)^{2} }

v_{2} \approx 11.573\,\frac{m}{s}

Now, the head associated with the pump is finally computed:

h_{pump} = \frac{175\,kPa-81.326\,kPa}{(1025\,\frac{kg}{m^{3}} )\cdot (9.807\,\frac{m}{s^{2}} )} +\frac{(11.573\,\frac{m}{s} )^{2}-(4.278\,\frac{m}{s} )^{2}}{2\cdot (9.807\,\frac{m}{s^{2}} )} + 1.8\,m

h_{pump} = 7.705\,m

The power that pump adds to the fluid is:

\dot W_{pump} = \dot V \cdot \rho \cdot g \cdot h_{pump}

\dot W_{pump} = (0.21\,m^{3})\cdot (1025\,\frac{kg}{m^{3}})\cdot (9.807\,\frac{m}{s^{2}})\cdot(7.705\,m)

\dot W_{pump} = 16264.922\,W\,(16.265\,kW)

4 0
3 years ago
Against which type of economic structure does conflict theory argue?
alisha [4.7K]

Answer:

b) socialism

Explanation:

Conflict theory focuses on the competition between groups within society over limited resources. Conflict theory views social and economic institutions as tools of the struggle between groups or classes, used to maintain inequality and the dominance of the ruling class.

HOPE IT HELPS!!!!!!!!!

4 0
3 years ago
Why do automotive technicians need to have good computer skills?​
Elden [556K]

Answer:

Just think about the number of computerized functions there are in modern automobiles.

Explanation:

8 0
3 years ago
The artifacts that expand what humans are able to do are called:.?
omeli [17]
Where you from?England has so many school subjects,but my country hasn’t got it.Do you like it
5 0
3 years ago
Dos capacitores de placas paralelas, idénticos, pero con la excepción de que uno tiene el doble de separación entre sus placas q
Charra [1.4K]

Las características de la capacitancia permiten encontrar los resultados para las diferentes preguntas

1) El capacitor con menor distancia entre las placas tiene mayor campo eléctrico.

2) El capacitor con menor distancia tiene mayor carga

3) El capacitor con menor distancia tiene mayor densidad de carga

Los capacitores son sistema que sirve para acumular carga, esa formado por placas conductoras separadas una distancia pequeña, la capacitancia es  

             C = \frac{Q}{DV} = \frac{\epsilon_o A}{d}  

Donde Q es a carga, ΔV la diferencia de potencial, A el area y d la separación de las placas.

Busquemos las respuestas para las diferentes preguntas:

1) Cual tiene mayor campo eléctrico.

El potencial y el campo eléctrico están relacionados

            ΔV = - E d

            E = - \frac{\Delta V}{d}

Indican que un capacitor tiene el doble de separación de las placas que el otro

Capacitor 1

          E = - \frac{\Delta V}{d_1}  

Capacitor 2

         d₂ = 2 d₁  

         E₂ = - \frac{\Delta V}{2d_1}  

         E₂= ½ E₁

Por lo tanto el capacitor con menor distancia entre las placas tiene mayor campo eléctrico.

2) Cual tiene mas carga

Busquemos la carga para cada capacitor  

           Q = ε₀ \frac{A \Delta V}{d}  

Capacitor 1

           Q₁ = (ε₀ A ΔV) \frac{1}{d_1}

Capacitor 2

           Q₂ = (ε₀ A Δv) \frac{1}{2d_1}

           

            Q₂ = Q₁/2

       

El capacitor con menor distancia tiene mayor carga

3) Cual tiene mayor densidad de energía

La densidad de energía en un capacitor esta dada por

         u_E  = ½ ε₀ E²  

calculamos para cada capacitor

           

Capacitor 1

         u_{E\  1} = ½ ε₀ E₁²

Capacitor 2

         u_{E 2} = ½ ε₀ (E₁/2)²

por lo cual el capacitor con menor distancia tiene mas densidad de carga

En conclusión con lass característica de capacitancia podemos encontrar los resultados para las diferentes preguntas

     1) El capacitor con menor distancia entre las placas tiene mayor campo eléctrico.

    2) El capacitor con menor distancia tiene mayor carga

    3) El capacitor con menor distancia tiene mas densidad de carga  

Aprender mas aquí:  brainly.com/question/22813371

7 0
3 years ago
Other questions:
  • Which factor is typically not a requisite feature of setting a career goal?
    15·1 answer
  • Refrigerant 134a at p1 = 30 lbf/in2, T1 = 40oF enters a compressor operating at steady state with a mass flow rate of 200 lb/h a
    14·1 answer
  • The volume of a right circular cone of radius r and height h is V = 1 3 πr 2h (a) (i) Find a formula for the instantaneous rate
    8·1 answer
  • If you log into the admin account on windows 10, will the admin be notified ? ​
    14·2 answers
  • Resistors of 150 Ω and 100 Ω are connected in parallel. What is their equivalent resistance?
    13·1 answer
  • For which of the following structures would a pile foundation be appropriate? (Select all that apply.)
    7·1 answer
  • In a database, a column is called a _____.<br> row<br> table<br> file<br> field
    9·2 answers
  • Would anyone be able to tell me what this is? it's for a water pump​
    13·1 answer
  • Process synchronization can be done on
    15·1 answer
  • The source term will affect all algebraic equations.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!