C11TRCNT - Bắn máy bay

Tác giả: RR

Ngôn ngữ: C++

#include <sstream>
#include <iomanip>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define FORN(i,a,b) for(int i=(a),_b=(b);i<_b;i++)
#define DOWN(i,a,b) for(int i=a,_b=(b);i>=_b;i--)
#define SET(a,v) memset(a,v,sizeof(a))
#define sqr(x) ((x)*(x))
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair

#define DEBUG(x) cout << #x << " = "; cout << x << endl;
#define PR(a,n) cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl;
#define PR0(a,n) cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl;
using namespace std;

//Buffer reading
int INP,AM,REACHEOF;
#define BUFSIZE (1<<12)
char BUF[BUFSIZE+1], *inp=BUF;
#define GETCHAR(INP) { \
    if(!*inp) { \
        if (REACHEOF) return 0;\
        memset(BUF,0,sizeof BUF);\
        int inpzzz = fread(BUF,1,BUFSIZE,stdin);\
        if (inpzzz != BUFSIZE) REACHEOF = true;\
        inp=BUF; \
    } \
    INP=*inp++; \
}
#define DIG(a) (((a)>='0')&&((a)<='9'))
#define GN(j) { \
    AM=0;\
    GETCHAR(INP); while(!DIG(INP) && INP!='-') GETCHAR(INP);\
    if (INP=='-') {AM=1;GETCHAR(INP);} \
    j=INP-'0'; GETCHAR(INP); \
    while(DIG(INP)){j=10*j+(INP-'0');GETCHAR(INP);} \
    if (AM) j=-j;\
}
//End of buffer reading

const long double PI = acos((long double) -1.0);

struct Point {
    int x, y;

    Point(int x = 0, int y = 0) : x(x), y(y) {}

    void read() {
        scanf("%d%d", &x, &y);
    }

    Point operator - (Point a) { return Point(x-a.x, y-a.y); }
} a[211];

int ccw(Point a, Point b, Point c) {
    b = b - a;
    c = c - a;
    long long t = b.x*(ll)c.y - b.y*(ll)c.x;
    if (t == 0) return 0;
    else return 1;
}

int cnt[211], res;

int main() {
    int n; scanf("%d", &n);
    FOR(i,1,n) a[i].read();

    FOR(i,1,n) FOR(j,i+1,n) FOR(k,j+1,n)
        if (ccw(a[i], a[j], a[k])) {
            res++;
            cnt[i]++;
            cnt[j]++;
            cnt[k]++;
        }
    printf("%d ", res);
    int best = 1;
    FOR(i,2,n) if (cnt[i] < cnt[best]) best = i;
    printf("%d\n", best);
    return 0;
}

Download