玲珑OJ1102 - 萌萌哒的第七题 【余弦定理】

    xiaoxiao2021-03-25  85

    1102 - 萌萌哒的第七题 Time Limit:2s Memory Limit:128MByte Submissions:371Solved:38 DESCRIPTION Feigay is doing some research about tornado. he drives a car and want to reach the center of the tornado. The center of tornado is (x0, y0) and it is moving at the speed is (vx,vy), Feigay is at location (x1, y1) now, his velocity is v. He wants to know whether he is possible to reach that point. INPUT The first line contains an integer T (<= 10000), indicates the number of testcase. Each test case consists of four lines, the first line contains two integers x0,y0 , the second line contains two integers x1,y1, the third line contains two integers vx,vy, the fourth line contains one integer v. The range of every number in the input file is 0 ~ 10000. OUTPUT For each test case, print a line contains "YES" if it is possible to reach the center or "NO" if impossible. SAMPLE INPUT 3 0 0 1 1 1 0 1 0 0 1 1 2 0 1 0 0 2 1 2 0 1 SAMPLE OUTPUT YES NO YES SOLUTION “玲珑杯”ACM比赛 Round #11

    WA到爆 好好复习了一遍余弦定理: cosα=b2+c2a22bc v0=|(vx,vy)| (x0,y0) 的速度 (x0,y0) (x1,y1) 的向量为 (x2,y2) |(x2,y2)|=dis α (vx,vy) (x2,y2) 的夹角 设 B⃗ =(vx,vy) , C⃗ =(x2,y2) cosα=B⃗ C⃗ |B⃗ ||C⃗ |

    假设在t时间相遇 根据余弦定理: 设 |B⃗ |=v0t,|C⃗ |=dis,|A⃗ |=vt cosα=|B⃗ |2|C⃗ |2|A⃗ |22|B⃗ ||C⃗ | (v20v2)t22v0discosαt+dis2=0 判断t是否有>0的解即可


    #include<iostream> #include<stdlib.h> #include<stdio.h> #include<string> #include<vector> #include<deque> #include<queue> #include<algorithm> #include<set> #include<map> #include<stack> #include<time.h> #include<math.h> #include<list> #include<cstring> #include<fstream> #include<queue> #include<sstream> //#include<memory.h> using namespace std; #define ll long long #define ull unsigned long long #define pii pair<int,int> #define INF 1000000007 #define pll pair<ll,ll> #define pid pair<int,double> const int inf=1e9+7; const double EPS=1e-9; bool slove(int x0,int y0,int x1,int y1,int vx,int vy,int v){ int v0_2=vx*vx+vy*vy; double v0=sqrt(v0_2); int x2=x1-x0,y2=y1-y0; int dis_2=x2*x2+y2*y2; double dis=sqrt(dis_2); double cosT=(x2*vx+y2*vy)/(dis*v0); double a=v0_2-v*v; double b=-2.0*v0*dis*cosT; double c=dis_2; double tmp=b*b-a*c*4.0; if(tmp<0){ return false; } double ans1=(-b+sqrt(tmp))/(2*a); double ans2=(-b-sqrt(tmp))/(2*a); return ans1>0||ans2>0; } int main() { //freopen("/home/lu/Documents/r.txt","r",stdin); //freopen("/home/lu/Documents/w.txt","w",stdout); int T; int x0,y0,x1,y1,vx,vy,v; scanf("%d",&T); while(T--){ scanf("%d%d%d%d%d%d%d",&x0,&y0,&x1,&y1,&vx,&vy,&v); puts(slove(x0,y0,x1,y1,vx,vy,v)?"YES":"NO"); } return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-25591.html

    最新回复(0)