QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#47700#4383. Laserckiseki#AC ✓93ms4716kbC++2.1kb2022-09-10 16:10:002022-09-10 16:10:01

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-10 16:10:01]
  • 评测
  • 测评结果:AC
  • 用时:93ms
  • 内存:4716kb
  • [2022-09-10 16:10:00]
  • 提交

answer

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


const int cx[4] = {1, 0, 1, 1};
const int cy[4] = {0, 1, 1, -1};

int calc(pair<int,int> p, int j) {
    return cx[j]*p.first + cy[j]*p.second;
}

pair<int,int> jiao(pair<int,int> p, int i, pair<int,int> q, int j) {
    int v1 = calc(p, i);
    int v2 = calc(q, j);

    int x = 0, y = 0;
    if (cy[j]*cx[i] - cy[i]*cx[j] != 0) {
        x = (cy[j] * v1 - cy[i] * v2) / (cy[j] * cx[i] - cy[i] * cx[j]);
        y = (cx[j] * v1 - cx[i] * v2) / (cy[i] * cx[j] - cy[j] * cx[i]);
    }
    return { x, y };
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vector<pair<int,int>> p(n);
        for (int i = 0; i < n; i++) {
            cin >> p[i].first >> p[i].second;
        }

        bool ans = false;
        for (int j = 0; j < 4; j++) {
            vector<int> mark(n);
            int f = -1;
            for (int i = 0; i < n; i++) {
                if (calc(p[i], j) == calc(p[0], j)) {
                    mark[i] = true;
                } else {
                    f = i;
                }
            }
            if (f == -1) {
                ans = true;
                break;
            } else {
                for (int k = 0; k < 4; k++) {
                    auto m = jiao(p[0], j, p[f], k);
                    bool ok = true;
                    for (int i = 0; i < n; i++) {
                        bool fnd = false;
                        for (int l = 0; l < 4; l++) {
                            if (calc(m, l) == calc(p[i], l))
                                fnd = true;
                        }
                        if (!fnd)
                            ok = false;
                    }
                    if (ok) {
                        // cerr << "m = " << m.first << ' ' << m.second << endl;
                        ans = true;
                        break;
                    }
                }
            }
        }

        if (ans) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 93ms
memory: 4716kb

input:

116
4
-10 0
10 0
5 5
-5 -5
4
-10 0
10 0
0 10
0 -10
4
-1 0
1 0
2 0
3 0
4
0 1
0 2
0 3
0 4
4
100 100
10000 10000
100000 100000
-100 -100
4
-100 100
-10000 10000
-100000 100000
100 -100
6
1 1
1 3
2 2
3 1
3 3
3 4
7
1 1
1 3
2 2
3 1
3 3
1 4
3 4
4
1236833 14678
1232056 9901
1237055 9790
1231834 15011
4
1236...

output:

YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
NO
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
NO
YES
NO...

result:

ok 116 lines