QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641768#7065. TriangleLoxilanteAC ✓2116ms3920kbC++142.1kb2024-10-14 23:13:062024-10-14 23:13:06

Judging History

你现在查看的是最新测评结果

  • [2024-10-14 23:13:06]
  • 评测
  • 测评结果:AC
  • 用时:2116ms
  • 内存:3920kb
  • [2024-10-14 23:13:06]
  • 提交

answer

#define F_C
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define int ll
using namespace std;
typedef long long ll;
template<typename tn = int> tn next(void) { tn k; cin>>k; return k; }
#ifndef LOCAL
#define D(...) 0
#endif
const double eps = 1e-8;
double k[5];
bool at[5];
struct Point
{
    double x, y;
} p[5];
bool eq(double a, double b)
{
    return a == b || fabs(a-b) <= eps;
}
double dis(Point a, Point b)
{
    return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}
double slope(Point a, Point b)
{
    return (b.y-a.y)/(b.x-a.x);
}
signed main(void)
{
    #ifdef LOCAL
//	freopen("C:\\Users\\Loxil\\Desktop\\IN.txt", "r", stdin);
//	freopen("C:\\Users\\Loxil\\Desktop\\OUT.txt", "w", stdout);
    #endif
    
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T = next();
    while(T--)
    {
        rep(i, 0, 4) cin>>p[i].x>>p[i].y, at[i] = 0;

        int at = -1, point = -1;
        rep(s, 0, 3)
        {
            int t = (s+1)%3;
            k[s] = slope(p[s], p[t]);
            if (eq(p[s].x, p[3].x) && eq(p[s].y, p[3].y)) point = s;
            else if ((eq(k[s], slope(p[3], p[s])) || eq(k[s], slope(p[s], p[3]))) 
                    && min(p[s].x, p[t].x) <= p[3].x && p[3].x <= max(p[s].x, p[t].x)
                    && min(p[s].y, p[t].y) <= p[3].y && p[3].y <= max(p[s].y, p[t].y)) at = s;
        }
        if (point != -1) { cout<<(p[(point+1)%3].x+p[(point+2)%3].x)/2<<' '<<(p[(point+1)%3].y+p[(point+2)%3].y)/2<<endl; continue; }
        if (at == -1) { cout<<-1<<endl; continue; }

        double r1 = dis(p[at], p[3])/dis(p[(at+1)%3], p[3]), r2 = r1<1 ? (r1+1)/2 : (r1-1)/r1/2;
        int u = (at+1+(r1>=1))%3, v = (u+1)%3;
        double ans1 = p[u].x+r2*(p[v].x-p[u].x), ans2 = p[u].y+r2*(p[v].y-p[u].y);
        cout<<fixed<<setprecision(12)<<ans1<<' '<<ans2<<endl;
    }
    
    return 0;
}
/*
1
0 3333
0 4444
1 2222
0 3566

1
72660 27465
49793 42194
22793 59586
70901 28598
 */

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3920kb

input:

2
0 0 1 1 1 0 1 0
0 0 1 1 1 0 2 0

output:

0.5 0.5
-1

result:

ok 3 numbers

Test #2:

score: 0
Accepted
time: 1319ms
memory: 3824kb

input:

999966
9456 15557 18451 3957 6242 20372 9855 5351
30245 31547 9979 4703 25914 19144 26670 11383
13855 0 24614 0 15860 11017 12445 0
27870 17680 4219 3554 9129 29072 28316 17893
3249 27269 12754 4923 31746 16860 14894 21576
6846 0 1915 0 25023 28721 10508 0
10110 11862 23224 10373 17715 8212 29474 11...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
21424.681479417704 13086.053910984188
-1
-1
18711.237990304100 10162.376377258704
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
28212.952134892577 245.817786238782
-1
-1
-1
-1
-1
-1
-1
-1
22604.575302188830 14546.128716105848
-1
-1
115...

result:

ok 1111378 numbers

Test #3:

score: 0
Accepted
time: 1319ms
memory: 3832kb

input:

999974
9228 16833 13143 23461 5117 7645 21359 13652
21313 3160 20333 1620 16288 7781 13315 10132
4372 0 27536 0 3207 8695 9983 0
21469 29998 19948 29904 30517 11141 14857 12881
11116 29172 16833 32095 18915 9448 22043 12275
32131 0 14304 0 16638 29018 2048 0
4695 4823 14130 2496 32676 4092 6363 2476...

output:

-1
-1
11482.990372016180 5737.223836381246
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
15409.841854934602 12451.427863654380
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
10828.971385779600 25347.334857323032
-1
-1
-1
-1
-1
18768.672699464696 12151.367150989890
-1
-1
-1...

result:

ok 1110866 numbers

Test #4:

score: 0
Accepted
time: 2116ms
memory: 3796kb

input:

1000000
54242 34392 23333 92971 5711 47765 54242 34392
24492 41078 36756 68794 2060 62118 14678 50283
12685 18891 59613 23256 26016 46755 59613 23256
85238 49611 95092 85360 45143 87657 95092 85360
72852 37174 39825 60628 32289 18423 72852 37174
95309 61613 1645 45877 78395 38196 95309 61613
92215 7...

output:

14522 70368
32900.888888888891 68052.222222222219
19350.500000000000 32823.000000000000
65190.500000000000 68634.000000000000
36057.000000000000 39525.500000000000
40020.000000000000 42036.500000000000
95183.500000000000 40970.500000000000
28582.000000000000 94834.500000000000
55598.000000000000 591...

result:

ok 2000000 numbers