-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy path爬山算法.c
69 lines (68 loc) · 1.41 KB
/
爬山算法.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 10010
#define eps 1e-8
#define pro 0.97
using namespace std;
int n;
struct Point
{
double x,y;
friend ostream& operator << (ostream &_,Point a)
{
printf("%.3lf %.3lf\n",a.x,a.y);
return _;
}
Point(){}
Point(double _x,double _y):x(_x),y(_y){}
Point operator + (const Point &a)
{return Point(x+a.x,y+a.y);}
Point operator - (const Point &a)
{return Point(x-a.x,y-a.y);}
Point operator * (double rate)
{return Point(x*rate,y*rate);}
double operator * (const Point &a)
{return x*a.x+y*a.y;}
};
struct GTY
{
Point p;
double g;
friend istream& operator >> (istream &_,GTY &a)
{
scanf("%lf%lf%lf",&a.p.x,&a.p.y,&a.g);
return _;
}
}pt[N];
double Get_Dis(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
Point Get_Direction(Point a)
{
Point p(0,0);
for(int i=1;i<=n;i++)
{
Point tmp=(pt[i].p-a)*(pt[i].g/Get_Dis(pt[i].p,a));
p=p+tmp;
}
return p;
}
Point Climb_Hill(Point now,double basement)
{
if(basement<eps)return now;
Point to=Get_Direction(now);
to=to*basement;
return Climb_Hill(now+to,basement*pro);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)cin>>pt[i];
Point Base_Point(1999.5,329.5);
Point ans=Climb_Hill(Base_Point,100000);
cout<<ans;
}