QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376726#868. Friendship Circlesfairyqq28WA 0ms7992kbC++142.2kb2024-04-04 15:50:122024-04-04 15:50:14

Judging History

This is the latest submission verdict.

  • [2024-04-04 15:50:14]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 7992kb
  • [2024-04-04 15:50:12]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
using namespace std;
const int N = 100010;
const double eps = 1e-8;
namespace geo{
    struct node{
        double x, y; int id;
        double val() {return sqrt(x * x + y * y);}
    } s[N], stk[N];
    node operator + (node x, node y){return node{x.x+y.x, x.y+y.y};}
    node operator - (node x, node y){return node{x.x-y.x, x.y-y.y};}
    double operator * (node x, node y) {return x.x*y.y - x.y*y.x;}

    int n, top;
    bool cmp(node x, node y){
        double tmp = (x - s[1]) * (y - s[1]);
        if(-eps <= tmp && tmp <= eps) return x.val() < y.val();
        return tmp > 0;
    }
    void calc(){
        top = 0;
        rep(i, 1, n)
            if(s[i].y < s[1].y || (s[i].y == s[1].y && s[i].x < s[1].x))
                swap(s[1], s[i]);
        sort(s + 2, s + n + 1, cmp);
        stk[++top] = s[1];
        rep(i, 2, n){
            while(top >= 2 && ((stk[top]-stk[top-1]) * (s[i]-stk[top-1])) < eps) top--;
            stk[++top] = s[i];
        }
    }
} using geo::node;

node inverse(const node& x, const node& y, const double &r){
    node ret = y - x; double tmp0 = ret.val();
    double tmp = r * r / tmp0 / tmp0;
    ret.x *= tmp, ret.y *= tmp;
    ret = ret + x; ret.id = y.id;
    return ret;
}

int n;
node a[N];
double r;

void solve(){
    scanf("%d", &n);
    rep(i, 1, n){
        scanf("%lf%lf", &a[i].x, &a[i].y);
        a[i].id = i - 1;
    }
    double mn = 4e9, mx = 0;
    rep(i, 2, n){
        mn = min(mn, (a[i] - a[1]).val());
        mx = max(mx, (a[i] - a[1]).val());
    }
    r = sqrt(mn * mx);
    // printf("%lf\n", r);
    geo::n = n;
    geo::s[1] = a[1];
    rep(i, 2, n) geo::s[i] = inverse(a[1], a[i], r);
    // rep(i, 2, n) printf("%lf %lf\n", geo::s[i - 1].x, geo::s[i - 1].y);
    geo::calc();
    int ans = geo::top;
    rep(i, 1, geo::top) if(!geo::stk[i].id) ans--;
    printf("%d ", ans);
    rep(i, 1, geo::top) if(geo::stk[i].id)
        printf("%d ", geo::stk[i].id);
    puts("");
}

int main(){
    int T; scanf("%d", &T); while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7992kb

input:

2
4
1 0
3 1
3 -2
7 0
5
0 0
-2 -1
2 2
-2 10
-1 11

output:

2 2 1 
3 1 2 3 

result:

wrong answer 2nd numbers differ - expected: '1', found: '2'