QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#785332#6812. Draw a triangleMartian148#WA 88ms3604kbC++202.1kb2024-11-26 17:33:462024-11-26 17:33:47

Judging History

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

  • [2024-11-26 17:33:47]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:3604kb
  • [2024-11-26 17:33:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
typedef i64 ll;
using i128 = __int128;

constexpr int flg[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

std::istream &operator >> (std::istream &is, i128 &n) {
    std::string s; is >> s;
    n = 0;
    for (char c : s) n = n * 10 + c - '0';
    return is;
}

std::ostream &operator << (std::ostream &os, i128 n) {
    std::string s;
    while (n) {
        s += '0' + n % 10;
        n /= 10;
    }
    std::reverse(s.begin(), s.end());
    return os << s;
}

struct Point {
    i128 x, y;
    Point(i128 x = 0, i128 y = 0) : x(x), y(y) {}
    bool operator == (Point &ohs) {
        return (x == ohs.x && y == ohs.y);
    }
};

typedef Point Vector;
Vector operator + (Vector A, Vector B) {return Vector(A.x + B.x, A.y + B.y);}
Vector operator - (Vector A, Vector B) {return Vector(A.x - B.x, A.y - B.y);}

i128 cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;}
i128 area2(Point A, Point B, Point C) {return cross(B - A, C - A);}

void print(i128 x) {
    if (x < 0) putchar('-'); x = -x;
    stack<int> st;
    do {
        st.push(x % 10);
        x /= 10;
    }while (x);
    while (!st.empty()) putchar(st.top() + '0'), st.pop();
}

void solve() {
    i64 x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    Point A(x1, y1), B(x2, y2);
    
    i128 min_area2 = -1;
    Point C;

    auto calc = [&] (Point P) -> void {
        if (P == A || P == B) return ;
        i128 now_area = area2(A, B, P);
        if (now_area == 0) return ;
        if (now_area < 0) now_area = -now_area;
        if (min_area2 == -1 || now_area < min_area2) {
            min_area2 = now_area;
            C = P;
        }
    };
    
    for (int k = 0; k < 4; k++) {
        calc(Point(A.x + flg[k][0], A.y + flg[k][1]));
        calc(Point(B.x + flg[k][0], B.y + flg[k][1]));
    }

    i64 Cx = C.x, Cy = C.y;
    cout << Cx << " " << Cy << '\n';
}

int main() {
    // freopen ("E.in", "r", stdin);
    // ios::sync_with_stdio(false);
    // cin.tie(0); cout.tie(0);
    int T; cin >> T;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 0 1 4
0 1 0 9
0 0 2 2

output:

0 0
-1 1
-1 0

result:

ok T=3 (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 88ms
memory: 3532kb

input:

50000
66620473 -33485015 66620223 -33485265
43307886 98029243 43307636 98028994
-88895230 -3180782 -88895480 -3181030
-90319745 20018595 -90319995 20018348
-56783257 84789686 -56783507 84789440
-81798038 90629147 -81798288 90628902
98942945 -939146 98942695 -939390
-42532151 -57203475 -42532401 -572...

output:

66620472 -33485015
43307885 98029243
-88895231 -3180782
-90319746 20018595
-56783258 84789686
-81798039 90629147
98942944 -939146
-42532152 -57203475
53500206 -30665605
27115053 46989134
-2657413 26865463
40614181 17923420
-47649905 96037711
92954294 -64534918
86508864 -51415166
-82017701 17392574
7...

result:

wrong answer wa on query #2 (test case 2)