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]
3 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]3 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
Explain the two advantages and the two disadvantages of fission as an energy source.
yawa3891 [41]

Answer with Explanation:

1) The advantages of fission energy are:

a) Higher concentration of energy : Concentration of energy or the energy density is defined as the amount of energy that is produced by burning a unit mass of the fuel. The nuclear energy obtained by fission has the highest energy density among all the other natural sources of energy such as coal,gas,e.t.c.

b) Cheap source of energy : The cost at which the energy is produced by a nuclear reactor after it is operational is the lowest among all the other sources of energy such as coal, solar,e.t.c

2) The disadvantages of fission energy are:

a) Highly dangerous residue: The fuel that is left unspent is highly radioactive and thus is very dangerous. Usually the residual material is taken deep into the earth for it's disposal.

b) It has high initial costs of design and development: The cost to design a nuclear reactor and to built one after it is designed is the most among all other types of energy sources and requires highly skilled personnel for operation.

6 0
2 years ago
An air compressor of mass 120 kg is mounted on an elastic foundation. It has been observed that, when a harmonic force of amplit
kupik [55]

Answer:

equivalent stiffness is 136906.78 N/m

damping constant is 718.96 N.s/m

Explanation:

given data

mass = 120 kg

amplitude = 120 N

frequency = 320 r/min

displacement = 5 mm

to find out

equivalent stiffness and damping

solution

we will apply here frequency formula that is

frequency ω = ω(n) √(1-∈ ²)      ......................1

here  ω(n) is natural frequency i.e = √(k/m)

so from equation 1

320×2π/60 = √(k/120) × √(1-2∈²)

k × ( 1 - 2∈²) = 33.51² ×120

k × ( 1 - 2∈²) = 134752.99    .....................2

and here amplitude ( max ) of displacement is express as

displacement = force / k  ×  (  \frac{1}{2\varepsilon \sqrt{1-\varepsilon ^2}})

put here value

0.005 = 120/k   ×  (  \frac{1}{2\varepsilon \sqrt{1-\varepsilon ^2}})  

k ×∈ × √(1-2∈²) = 1200       ......................3

so by equation 3 and 2

\frac{k\varepsilon \sqrt{1-\varepsilon^2})}{k(1-2\varepsilon^2)} = \frac{12000}{134752.99}

\varepsilon^{2} - \varepsilon^{4}  = 7.929 * 10^{-3} - 0.01585 * \varepsilon^{2}

solve it and we get

∈ = 1.00396

and

∈ = 0.08869

here small value we will consider so

by equation 2 we get

k × ( 1 - 2(0.08869)²) = 134752.99

k  = 136906.78 N/m

so equivalent stiffness is 136906.78 N/m

and

damping is express as

damping = 2∈ √(mk)

put here all value

damping = 2(0.08869) √(120×136906.78)

so damping constant is 718.96 N.s/m

7 0
3 years ago
Technician A says independent shops are not affiliated with vehicle manufacturers, but it is easy for technicians who work in th
KatRina [158]

Answer:

b

Explanation:

i did it yeater dayajsbs

8 0
3 years ago
A strain gage is mounted at an angle of 30° with respect to the longitudinal axis of the cylindrical pressure. The pressure vess
GuDViN [60]

Answer:

1790 μrad.

Explanation:

Young's modulus, E is given as 10000 ksi,

μ is given as 0.33,

Inside diameter, d = 54 in,

Thickness, t = 1 in,

Pressure, p = 794 psi = 0.794 ksi

To determine shear strain, longitudinal strain and circumferential strain will be evaluated,

Longitudinal strain, eL = (pd/4tE)(1 - 2μ)

eL = (0.794 x 54)(1 - 0.66)/(4 x 1 x 10000)

eL = 3.64 x 10-⁴ radians

Circumferential strain , eH = (pd/4tE)(2-μ)

eH = (0.794 x 54)(2 - 0.33)/(4 x 1 x 10000)

eH = 1.79 x 10-³ radians

The maximum shear strain is 1790 μrad.

4 0
3 years ago
Do heavier cars really use more gasoline? Suppose a car is chosen at random. Let x be the weight of the car (in hundreds of poun
Alex17521 [72]

Answer:

Answer is explained in the explanation section below.

Explanation:

Solution:

Note: This question is incomplete and lacks necessary data to solve. But I have found the similar question on the internet. So, I will be using the data from that question to solve this question for the sack of concept and understanding.

Data Given:

x = 27 , 44 , 32 , 47, 23 , 40, 34, 52

y = 30, 19,  24,  13 , 29,  19,  21,  14

It is given that,

∑x = 299

∑y = 167

∑x^{2} = 11887

∑y^{2} = 3773

We are asked to verify the above values manually in this question.

So,

1. ∑x = 299

Let's verify it:

∑x = 27 + 44 + 32 + 47 + 23 + 40 + 34 + 52

∑x = 299

Yes, it is equal to the given value. Hence, verified.

2. ∑y = 167

Let's verify it:

∑y = 30 + 19 +  24 + 13 + 29 + 19 +  21 +  14

∑y = 169

No, it is not equal to the given value.

3. ∑x^{2} = 11887

Let's verify it:

For this to find,  first we need to square all the value of x individually and then add them together to verify.

∑x^{2} = 27^{2} + 44^{2} + 32^{2} + 47^{2} + 23^{2} + 40^{2} + 34^{2} + 52^{2}

∑x^{2} = 11,887

Yes, it is equal to the given value. Hence, verified.

4. ∑y^{2} = 3773

Let's verify it:

Again, for this we need to find the squares of all the y values and then add them together to verify it.

∑y^{2} = 30^{2} + 19^{2} +  24^{2} + 13^{2} + 29^{2} + 19^{2} +  21^{2} +  14^{2}

∑y^{2}  = 3,845

No, it is not equal to the given value.

4 0
2 years ago
Other questions:
  • A force of 16,000 will cause a 1 1 bar of magnesium to stretch from 10 to 10.036 . Calculate the modulus of elasticity in . (Ent
    6·1 answer
  • Ok I need a new laptop but I'm not sure which one. The Surface laptop 3 is better in many fields like the camera, speaker, audio
    14·1 answer
  • - If you overload the rear portion of you vehicle &amp; it's raining out, your car could easily:
    14·1 answer
  • Add my sc please?.<br><br> kindacracked
    12·2 answers
  • Sam, a carpenter, is asked to identify the abilities he has that are important to his work. What are the top abilities he might
    9·2 answers
  • What have you learned about designing solutions? How does this apply to engineering? Think of some engineering solutions that st
    15·1 answer
  • What is the output of the following program fragment. Choose appropriate data-types of variables to match output.
    10·1 answer
  • A heating system must maintain the interior of a building at TH = 20 °C when the outside temperature is TC = 2 °C. If the rate o
    10·1 answer
  • A 1/4" nut driver with a 1.52 inch diameter handle is used to install a 14" 6 UNC
    13·1 answer
  • All of the following are drum brake components mounted to the backing plate, EXCEPT:
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!