A representative of Richardson Health Department wants to investigate optimal al
ID: 3914292 • Letter: A
Question
A representative of Richardson Health Department wants to investigate optimal allocation strategy of ambulances in case of emergency. Write a program that can assign all demand points to a nearest dispatch station given the location information below. Use loop statement(s) and array(s) W Plano Pkwy WPlano Pn George Bush Tumpik Central Market 30 10 24 Renner Rd ankford IR Frankford Rd 1canyon Creeka Country Club 20 Landing Dallas University Village O The University Richardsonof Texas at Dallas 25 30 19 2 17 The Home Depot 10 Creek 11 12 13 14 15 16 17 25 21 28 30 31 Station 1 32 bell Rd RdW Campbell Rd 3 (8,16) Station 2 (35,13) tno 31 J.J Pearce High School 35 26 35 15 Preston Ridge Trail Park Important Notes: Assumed that the user always correctly enters the inputExplanation / Answer
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n=17;
int a[17]={1,3,5,9,11,11,9,17,22,25,21,28,30,31,8,26,35};
int b[17]={5,30,10,24,22,20,4,25,30,19,5,32,31,1,35,2,15};
int x1,x2,y1,y2;// (x1,y1) is station1 locatin and (x2,y2) is station2 location
int z,d,z1,d1,g,r,g1,r1,f,f1;
x1=8;
y1=16;
x2=35;
y2=13;
vector < pair <int,int> > s1,s2;//store nearest point in a vector s1 for station1 and s2 for station2
for(int i=0;i<n;i++)
{
z=abs(a[i]-x1);
z1=abs(b[i]-y1);
d=abs(a[i]-x2);
d1=abs(b[i]-y2);
g=pow(z,2);
g1=pow(z1,2);
r=pow(d,2);
r1=pow(d1,2);
f=sqrt((g+g1));
f1=sqrt((r+r1));//caluculating distance from each point to station1 and station2
if(f<f1) //if station1 is nearer
{
s1.push_back( make_pair(a[i],b[i]));
}
else if(f>f1)//if station2 is nearer
{
s2.push_back( make_pair(a[i],b[i]) );
}
else //if both are equal
{
s1.push_back( make_pair( a[i],b[i]) );
s2.push_back( make_pair(a[i],b[i]));
}
}
cout<<"The points nearer to station1 are"<<endl;
for(int i=0;i<s1.size();i++)
{
cout<<"("<<s1[i].first<<","<<s1[i].second<<")"<<endl;
}
cout<<"The points nearer to station2 are"<<endl;
for(int i=0;i<s2.size();i++)
{
cout<<"("<<s2[i].first<<","<<s2[i].second<<")"<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.