-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrobot.cpp
More file actions
52 lines (40 loc) · 961 Bytes
/
robot.cpp
File metadata and controls
52 lines (40 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
double distance(double x1, double y1,double x2,double y2)
{
double t=(x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
return (sqrt(t));
}
int main()
{
int N;
int loc=0;
scanf("%d",&N);
int p[N+1];
double x1[N+1],y1[N+1],x2[N+1],y2[N+1];
for(int i=0;i<N;i++)
{
scanf("%lf%lf%lf%lf",&x1[i],&y1[i],&x2[i],&y2[i]);
scanf("%d",&p[i]);
}
double current=999999;
double dist=999999;
for(int i=0;i<N;i++)
{
if((x1[i]==0 &&y1[i]==0) || (x2[i]==0 && y2[i]==0))
{
loc=i;
dist=distance(x1[i],y1[i],x2[i],y2[i]);
break;
}
current=distance(x1[i],y1[i],x2[i],y2[i]);
if(current<dist && p[i])
{
dist=current;
loc=i;
}
}
printf("%d\n",loc+1);
printf("%.2lf\n", dist);
return 0;
}