[2020 cattle customer base algorithm winter training camp 2] D- triangular number

This question really do spit. Not long ago, because I have been studying polar angle sort. So this question intend to use polar angle sort.

After After writing out a I can not find the bug (mad personal

After this question has been Sike. Then I looked for two hours. Still can not find. I vomited. After a very shameless can only help big brother.

After chiefs issued a soul asked: This is not the biggest square edge is greater than the remaining sides of the square and after special judge collinear like it? (Gangster humiliate me some more XD

I directly orgasm. This question is subsequently seconds.

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

typedef long long ll;
const int maxn = 500 + 5;

struct node {
    double x,y;
} p[maxn];
int n;

double a[5];

double num(int x,int y) {
    return (p[x].x - p[y].x) * (p[x].x - p[y].x) + (p[x].y - p[y].y) * (p[x].y - p[y].y)  ;
}


int main ()
{
    cin >> n;
    for(int i = 1; i <= n; i ++) 
        cin >> p[i].x >> p[i].y;
    
    ll res = 0;
    for(int i = 1; i <= n; i ++) {
        for(int j = i + 1; j <= n; j ++) {
            for(int k = j + 1; k <= n; k ++) {
                //特判三点共线
                if((p[k].y - p[i].y) * (p[j].x-p[i].x) - (p[j].y-p[i].y)*(p[k].x-p[i].x) == 0) 
                    continue;
                a[0] = num(i,j),a[1] = num(i,k),a[2] = num(j,k);
                sort(a,a + 3);
                if(a[0] + a[1] < a[2]) res ++;
            }
        }
    }
    cout << res << endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Vikyanite/p/12286331.html