Hướng dẫn giải của VM 13 Bài 06 - Nhật thực sao Kim


Chỉ dùng lời giải này khi không có ý tưởng, và đừng copy-paste code từ lời giải này. Hãy tôn trọng người ra đề và người viết lời giải.
Nộp một lời giải chính thức trước khi tự giải là một hành động có thể bị ban.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const double PI = acos(-1.0), EPS = 1e-13;

int main()
{
    double x1, y1, v1, x2, y2, v2, difTheta;
    cin >> x1 >> y1 >> v1 >> x2 >> y2 >> v2;
    double r1 = sqrt(x1 * x1 + y1 * y1), r2 = sqrt(x2 * x2 + y2 * y2);
    v1 /= r1; v2 /= r2;
    double theta1 = atan2(y1, x1), theta2 = atan2(y2, x2);

    if (fabs(v1 - v2) < EPS)
    {
        if (fabs(theta1 - theta2) < EPS) puts("0");
        else puts("-1");
    }
    else
    {
        difTheta = theta2 - theta1;
        if (v1 < v2) difTheta = -difTheta;
        while (difTheta < 0) difTheta += PI * 2;
        printf("%.9lf\n", difTheta / fabs(v1 - v2));
    }
}

Code mẫu của happyboy99x

#include<iostream>
#include<cstdio>
#include<complex>
#include<cmath>
using namespace std;

typedef complex<double> point;

int main() {
    long long xv, xe, yv, ye, vv, ve;
    cin >> xv >> yv >> vv >> xe >> ye >> ve;
    if(xv == 0 && yv == 0) printf("0\n");
    else {
        double alpha1 = arg(point(xv, yv));
        double alpha2 = arg(point(xe, ye));
        double omega1 = vv / abs(point(xv, yv));
        double omega2 = ve / abs(point(xe, ye));
        if(abs(omega1 - omega2) <= 1e-9) {
            if(xv * ye == xe * yv && xv * xe + yv * ye > 0) printf("0\n"); 
            else printf("-1\n");
        } else {
            double res = (alpha1 - alpha2) / (omega2 - omega1);
            double delta = 2 * M_PI / abs(omega2 - omega1);
            while(res < 0) res += delta;
            printf("%.10lf\n", res);
        }
    }
    return 0;
}

Code mẫu của RR

#include <sstream>
#include <iomanip>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define FORN(i,a,b) for(int i=(a),_b=(b);i<_b;i++)
#define DOWN(i,a,b) for(int i=a,_b=(b);i>=_b;i--)
#define SET(a,v) memset(a,v,sizeof(a))
#define sqr(x) ((x)*(x))
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair

#define DEBUG(x) cout << #x << " = "; cout << x << endl;
#define PR(a,n) cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl;
#define PR0(a,n) cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl;
using namespace std;

//Buffer reading
int INP,AM,REACHEOF;
const int BUFSIZE = (1<<12) + 17;
char BUF[BUFSIZE+1], *inp=BUF;
#define GETCHAR(INP) { \
    if(!*inp && !REACHEOF) { \
        memset(BUF,0,sizeof BUF);\
        int inpzzz = fread(BUF,1,BUFSIZE,stdin);\
        if (inpzzz != BUFSIZE) REACHEOF = true;\
        inp=BUF; \
    } \
    INP=*inp++; \
}
#define DIG(a) (((a)>='0')&&((a)<='9'))
#define GN(j) { \
    AM=0;\
    GETCHAR(INP); while(!DIG(INP) && INP!='-') GETCHAR(INP);\
    if (INP=='-') {AM=1;GETCHAR(INP);} \
    j=INP-'0'; GETCHAR(INP); \
    while(DIG(INP)){j=10*j+(INP-'0');GETCHAR(INP);} \
    if (AM) j=-j;\
}
//End of buffer reading

const long double PI = acos((long double) -1.0);

int main() {
    long double x1, y1, v1, x2, y2, v2;
    while (cin >> x1 >> y1 >> v1 >> x2 >> y2 >> v2) {
        long double a1 = atan2(y1, x1), a2 = atan2(y2, x2);
        long double r1 = sqrt(x1*x1 + y1*y1), r2 = sqrt(x2*x2 + y2*y2);

        v1 /= r1; v2 /= r2;

        if (fabs(a1 - a2) < 1e-8) puts("0");
        else if (fabs(v1 - v2) < 1e-8) puts("-1");
        else {
            long double diff = a2 - a1;
            if (v1 < v2) diff = -diff;
            while (diff < 0) diff += 2 * M_PI;
            cout << (fixed) << setprecision(9) << diff / fabs(v1 - v2) << endl;
        }
    }
    return 0;
}

Code mẫu của skyvn97

#include<cstdio>
#include<cmath>
#define EPS   1e-9
#define PI   acos(-1.0)
double X1,Y1,X2,Y2;
double V1,V2,W1,W2;
double A1,A2,DA;
double omg(const double &x,const double &y) {
    if (fabs(y)<=EPS && x-EPS>0) return (0.0);
    if (fabs(y)<=EPS && x+EPS<0) return (PI);   
    if (fabs(x)<=EPS && y-EPS>0) return (PI/2.0);
    if (fabs(x)<=EPS && y+EPS<0) return (3.0*PI/2.0);
    if (x-EPS>0 && y-EPS>0) return (atan(y/x));
    if (x+EPS<0 && y-EPS>0) return (PI-atan(-y/x));
    if (x+EPS<0 && y+EPS<0) return (PI+atan(y/x));
    if (x-EPS>0 && y+EPS<0) return (2.0*PI-atan(-y/x));
}
void process(void) {
    scanf("%lf",&X1);
    scanf("%lf",&Y1);
    scanf("%lf",&V1);
    scanf("%lf",&X2);
    scanf("%lf",&Y2);
    scanf("%lf",&V2);
    A1=omg(X1,Y1);
    A2=omg(X2,Y2);
    if (fabs(A1-A2)<=EPS) {
        printf("0.00000000");
        return;
    }
    W1=V1/hypot(X1,Y1);
    W2=V2/hypot(X2,Y2);
    if (W1>W2+EPS) {
        if (A2>A1+EPS) DA=A2-A1;
        else DA=2.0*PI-A1+A2;
        printf("%.8lf",DA/fabs(W1-W2));
        return;
    }
    if (W2>W1+EPS) {
        if (A1>A2+EPS) DA=A1-A2;
        else DA=2.0*PI-A2+A1;
        printf("%.8lf",DA/fabs(W2-W1));
        return;
    }
    printf("-1");   
}
int main(void) {
    process();
    return 0;
}

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.