You have been given longitude and latitude of locations from where the channels are going to be broadcasted. You also get the height of tower from which these channels are broadcasted. Moreover, you have been given the location of your friend Jason. You have to calculate how many connections he can make to the towers. Take Radius of earth= 6371 KM. All the computation has to be accurate up to 6 digits after the decimal point. Constraints 1 <= N < 10^5 Input First line contains integer N denoting the number of locations from where the channel is going to be broadcasted Second line contains N space-separated decimal values denoting latitudes Third line contains N space-separated decimal values denoting longitudes Fourth line contains N space-separated integer values denoting the height of tower from which channels are broadcasted Fifth Line contains two space-separated decimal values denoting latitude, longitude of Jason's location Output Print the number of channels Jason can connect with
Answers
Answer:
8ujb the use this message in context in this case is my
Answer:
#include <iostream>
#include <cmath>
using namespace std;
double R = 6371000.00000;//m
double PI = 2 * acos(0.0);
double getRange(int h){
return R*(acos(R/(R+h*1000))); //h is in km
}
double getDist(double lat1, double lat2, double lon1, double lon2){
double phi1 = lat1 * PI/180; // φ, λ in radians
double phi2 = lat2 * PI/180;
double diffPhi = (lat2-lat1) * PI/180;
double diffLamb = (lon2-lon1) * PI/180;
double a = sin(diffPhi/2) * sin(diffPhi/2) +
cos(phi1) * cos(phi2) *
sin(diffLamb/2) * sin(diffLamb/2);
double c = 2 * atan2(sqrt(a), sqrt(1-a));
double d = R * c; // in metres
return d;
}
int main()
{
int n;
double lats[100000];
double lon[100000];
int h[100000];
cin>>n;
double Jognlat, Johnlon;
for(int i=0;i<n;++i){
cin>>lats[i];
}
for(int i=0;i<n;++i){
cin>>lon[i];
}
for(int i=0;i<n;++i){
cin>>h[i];
}
cin>>Jognlat>>Johnlon;
int ans =0;
for(int i=0;i<n;++i){
cout<<"dist: "<<getDist(Jognlat, lats[i], Johnlon, lon[i])<<endl;
//cout<<"getRange"<<getRange(h[i])<<endl;
if(getDist(Jognlat, lats[i], Johnlon, lon[i])<=getRange(h[i]))
++ans;
}
cout<<ans<<endl;
return 0;
}
Explanation:
actually first you need to calculate the arc distance between john and tower given their lon and lat which is what getDist() is doing. Then you need to determine the range of the tower which can be determined by the line of sight of the tower i.e throwing staright line from the head of the tower and marking the farthest point it can touch and then calculating the arc distance from tower to that point which will be our range. RANGE = acos(R/(R+H))*R.
then we simply check if distance<=RANGE . :-)