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
Find the mathematical equation for SF distribution and BM diagram for the beam shown in figure 1.​
Novosadov [1.4K]

Answer:

i) SF: v(x) = \frac{(w_0* x )^2}{2L}

ii) BM : = \frac{(w_0*x)^3}{6L}

Explanation:

Let's take,

\frac{y}{w_0} = \frac{x}{L}

Making y the subject of formula, we have :

y = \frac{x}{L} * w_0

For shear force (SF), we have:

This is the area of the diagram.

v(x) = \frac{1}{2} * y = \frac{1}{2} * \frac{x}{L} * w_0

= \frac{(w_0* x )^2}{2L}

The shear force equation =

v(x) = \frac{(w_0* x )^2}{2L}

For bending moment (BM):

BM = v(x) * \frac{x}{3}

= \frac{(w_0* x )^2}{2L}  * \frac{x}{3}

= \frac{(w_0*x)^3}{6L}

The bending moment equation =

= \frac{(w_0*x)^3}{6L}

5 0
4 years ago
What are the philological elements of interior design most like?
sp2606 [1]

Answer:

Ea public address glven via the intercom system of a large buildingxplanation:

7 0
2 years ago
Write a SELECT statement that returns the same result set as this SELECT statement. Substitute a subquery in a WHERE clause for
sergiy2304 [10]

Answer:

SELECT distinct VendorName FROM Vendors

WHERE VendorID IN (

SELECT VendorID FROM Invoices

)

Explanation:

6 0
3 years ago
The fracture strength of glass may be increased by etching away a thin surface layer. It is believed that the etching may alter
Korvikt [17]

Answer:

the ratio of the etched to the original crack tip radius is 30.24

Explanation:

Given the data in the question;

we determine the initial fracture stress using the following expression;

(σf)₁ = 2(σ₀)₁ [ α₁/(p_t)₁ ]^{1/2 ----- let this be equation 1

where; (σ₀)₁ is the initial fracture strength

(p_t)₁ is the original crack tip radius

α₁ is the original crack length.

first, we determine the final crack length;

α₂ = α₁ - 16% of α₁

α₂ = α₁ - ( 0.16 × α₁)

α₂ = α₁ - 0.16α₁

α₂ = 0.84α₁

next, we calculate the final fracture stress;

the fracture strength is increased by a factor of 6;

(σ₀)₂ = 6( σ₀ )₁

Now, expression for the final fracture stress

(σf)₂ = 2(σ₀)₂ [ α₂/(p_t)₂ ]^{1/2 ------- let this be equation 2

where (p_t)₂ is the etched crack tip radius

value of fracture stress of glass is constant

Now, we substitute 2(σ₀)₁ [ α₁/(p_t)₁ ]^{1/2 from equation for (σf)₂  in equation 2.

0.84α₁ for α₂.

6( σ₀ )₁ for (σ₀)₂.

∴

2(σ₀)₁ [ α₁/(p_t)₁ ]^{1/2  = 2(6( σ₀ )₁) [ 0.84α₁/(p_t)₂ ]^{1/2  

divide both sides by 2(σ₀)₁

[ α₁/(p_t)₁ ]^{1/2  =  6 [ 0.84α₁/(p_t)₂ ]^{1/2

[ 1/(p_t)₁ ]^{1/2  =  6 [ 0.84/(p_t)₂ ]^{1/2

[ 1/(p_t)₁ ]  =  36 [ 0.84/(p_t)₂ ]

1 / (p_t)₁ = 30.24 / (p_t)₂

(p_t)₂ = 30.24(p_t)₁

(p_t)₂/(p_t)₁ = 30.24

Therefore, the ratio of the etched to the original crack tip radius is 30.24

6 0
3 years ago
Describe the cycle that purifies drinking water. 40 points
Sunny_sXe [5.5K]
Umm the Water cycle sorry I’m trying
5 0
3 years ago
Read 2 more answers
Other questions:
  • Consider a cubical furnace with a side length of 3 m. The top surface is maintained at 700 K. The base surface has emissivity of
    13·1 answer
  • Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Assuming the item is pai
    11·1 answer
  • Determine the resultant normal force across the cross section at point B. Express your answer to three significant figures and i
    6·1 answer
  • What is the federal E-Rate program?
    11·1 answer
  • A belt drive was designed to transmit the power of P=7.5 kW with the velocity v=10m/s. The tensile load of the tight side is twi
    14·1 answer
  • Explain the underlying physical reason why when we conduct various heat treatments on 1018 steel we expect the modulus of elasti
    8·1 answer
  • Architects design roads.<br><br> A. True<br> B. False
    9·2 answers
  • What does polarity give you information about?
    10·1 answer
  • 10) A pressure sensor consisting of a diaphragm with strain gauges bonded to its surface has the following information in its sp
    12·1 answer
  • Describe the first case where the power of synthesis was used to solve design problems.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!