Submission #1690643


Source Code Expand

#include<bits/stdc++.h>
#define N 200000
using namespace std;
struct line {
    int A, B, C, n;
    double p;
} L[N];
int t[N], n;

bool cmpX(line a, line b) {
    return a.A * b.B > b.A * a.B;
}
bool cmp(line a, line b) {
    return a.p < b.p;
}
int lb(int x) {
    return x & (-x);
}
double calc(double x, int i) {
    return ((double)L[i].C - (double)L[i].A * x) / L[i].B;
}
void add(int x) {
    for(; x <= n; x += lb(x)) t[x]++;
}
int ask(int x) {
    int ret = 0;
    for(; x > 0; x -= lb(x)) ret += t[x];
    return ret;
}

int ch(double mid) {
    for(int i = 1; i <= n; i++) L[i].p = calc(mid, i);
    sort(L + 1, L + n + 1, cmp);
    for(int i = 1; i <= n; i++) t[i] = 0;
    int ret = 0;
    for(int i = 1; i <= n; i++) {
        ret += ask(L[i].n);
        add(L[i].n);
    }
    return ret;
}

double sol() {
    double l = -1e9, r = 1e9;
    for(int i = 1; i <= 80; i++) {
        double mid = (l + r) / 2;
        int tmp = ch(mid);
        if (tmp + tmp < n * (n - 1) / 2) l = mid;
        else r = mid;
    }
    return l;
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) scanf("%d%d%d", &L[i].A, &L[i].B, &L[i].C);
    for(int i = 1; i <= n; i++)
        if (L[i].B < 0) L[i].A *= -1, L[i].B *= - 1, L[i].C *= -1;
    sort(L + 1, L + n + 1, cmpX);
    for(int i = 1; i <= n; i++) L[i].n = i;
    double X = sol();
    for(int i = 1; i <= n; i++) swap(L[i].A, L[i].B);
    for(int i = 1; i <= n; i++)
        if (L[i].B < 0) L[i].A *= -1, L[i].B *= - 1, L[i].C *= -1;
    sort(L + 1, L + n + 1, cmpX);
    for(int i = 1; i <= n; i++) L[i].n = i;
    double Y = sol();
    printf("%.20f %.20f\n", X, Y);
}

Submission Info

Submission Time
Task E - CARtesian Coodinate
User lijingze8
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1704 Byte
Status AC
Exec Time 680 ms
Memory 1280 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:56:75: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%d%d%d", &L[i].A, &L[i].B, &L[i].C);
                                                                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 35
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 676 ms 1280 KB
02.txt AC 676 ms 1280 KB
03.txt AC 675 ms 1280 KB
04.txt AC 674 ms 1280 KB
05.txt AC 676 ms 1280 KB
06.txt AC 675 ms 1280 KB
07.txt AC 675 ms 1280 KB
08.txt AC 676 ms 1280 KB
09.txt AC 677 ms 1280 KB
10.txt AC 675 ms 1280 KB
11.txt AC 675 ms 1280 KB
12.txt AC 674 ms 1280 KB
13.txt AC 676 ms 1280 KB
14.txt AC 676 ms 1280 KB
15.txt AC 676 ms 1280 KB
16.txt AC 676 ms 1280 KB
17.txt AC 676 ms 1280 KB
18.txt AC 676 ms 1280 KB
19.txt AC 675 ms 1280 KB
20.txt AC 675 ms 1280 KB
21.txt AC 555 ms 1280 KB
22.txt AC 556 ms 1280 KB
23.txt AC 677 ms 1280 KB
24.txt AC 679 ms 1280 KB
25.txt AC 680 ms 1280 KB
26.txt AC 677 ms 1280 KB
27.txt AC 1 ms 256 KB
28.txt AC 1 ms 256 KB
29.txt AC 1 ms 256 KB
30.txt AC 1 ms 256 KB
31.txt AC 1 ms 256 KB
32.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB