2018多校第6场 1013 hdu6373 Pinball

题目链接:Pinball

题解:

代码比较挫

 1 #include<bits/stdc++.h>
 2 #define pi acos(-1)
 3 #define eps 1e-10
 4 //double add(double a,double b)
 5 //{
 6 //    if(abs(a+b)<eps*(abs(a)+abs(b)))return 0;
 7 //    return a+b;
 8 //}
 9 using namespace std;
10 const int maxn=1e5+5;
11 int a,b;
12 struct P
13 {
14     double x,y;
15     P(){}
16     P(double x,double y):x(x),y(y){}
17     P operator+(P p)
18     {
19         return P(x+p.x,y+p.y);
20     }
21     P operator-(P p)
22     {
23         return P(x-p.x,y-p.y);
24     }
25     P operator*(double d)
26     {
27         return P(x*d,y*d);
28        // return add(x*p.x,y*p.y)
29     }
30     double dot(P p)
31     {
32         return x*p.x+y*p.y;
33     }
34     double det(P p)
35     {
36         return x*p.y-y*p.x;
37     }
38 };
39 bool on_seg(P p1,P p2,P q)
40 {
41     return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<=0;
42 }
43 P intersection(P p1,P p2,P q1,P q2)//两线交点
44 {
45     return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
46 }
47 double dis(P p,P q)
48 {
49     return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));
50 }
51 int main()
52 {
53     int T;
54     scanf("%d",&T);
55     double g=9.80,g1,g2,cn,sn;
56     while(T--)
57     {
58         int a,b,x,y;
59         scanf("%d %d %d %d",&a,&b,&x,&y);
60         cn=1.0*a/sqrt(a*a+b*b);
61         sn=1.0*b/sqrt(a*a+b*b);
62         g1=cn*g;g2=sn*g;
63         P p1,p2,p3,p4,pp;
64         p1.x=-a;p1.y=b;
65         p2.x=0;p2.y=0;
66         p3.x=x;p3.y=y;
67         p4.x=x+1;p4.y=y+1.0*a/b;
68         pp=intersection(p1,p2,p3,p4);
69         double len1=dis(pp,p3),len2=dis(pp,p2);
70         double t1=2*sqrt(2*g1*len1)/g1;
71         double t2=sqrt(2*len2/g2);
72         double ans=t2/t1;
73         ans+=0.5;
74         int an=ans;
75         printf("%d\n",an);
76     }
77 }

猜你喜欢

转载自www.cnblogs.com/lhclqslove/p/9448654.html