1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include <bits/stdc++.h> #define Orz ios::sync_with_stdio(0),cin.tie(0) #define rep(i,a,b) for(int i=a;i<=b;i++) #define pii pair<int,int> #define pdd pair<double,double> #define int long long #define ll long long #define ld long double #define N 100001 #define all(x) x.begin(),x.end() #define eps 1e-9 #define x first #define y second
using namespace std;
struct pt{ int x,y; bool operator < (pt b){ if(x == b.x)return y < b.y; return x < b.x; } bool operator > (pt b){ if(x == b.x)return y > b.y; return x > b.x; } bool operator == (pt b){ if(x-b.x == 0 && y-b.y == 0)return true; return false; } pt operator+(pt b) {return {x + b.x, y + b.y};} pt operator-(pt b) {return {x - b.x, y - b.y};} int operator^(pt b) {return x * b.y - y * b.x;} int operator*(pt b) {return x * b.x + y * b.y;} };
vector<pt> p,temp,pp; vector<int> cnt; int n,ans = 0;
bool cmp(pt a, pt b){ bool f1 = a < pt{0,0}; bool f2 = b < pt{0,0}; if(f1 != f2)return f1 < f2; return (a ^ b) > 0; }
int solve(pt id){ pp.clear();cnt.clear();temp.clear(); for(pt i : p){ pt cur = i - id; if(cur == pt{0,0})continue; temp.push_back(cur); } sort(all(temp),cmp); pp.push_back(temp[0]); cnt.push_back(1); int len = temp.size(); rep(i,1,len-1){ int cross = temp[i]^temp[i-1],dot = temp[i]*temp[i-1]; if(cross == 0 && dot >= 0)cnt[cnt.size()-1] += 1; else {pp.push_back(temp[i]);cnt.push_back(1);} } len = pp.size(); rep(i,0,len-1){ pp.push_back(pp[i]); cnt.push_back(cnt[i]); } int ans = 0,p1 = 0; rep(i, 0, len-1){ while(p1 < i+len && (pp[i]^pp[p1]) >= 0 && (pp[i]*pp[p1]) > 0)p1 += 1; if((pp[i]^pp[p1]) > 0 && (pp[i]*pp[p1]) == 0)ans += cnt[i]*cnt[p1]; } return ans; }
signed main(){ Orz; while(cin>>n){ if(n == 0)break; p.assign(n,{0,0}); rep(i,0,n-1)cin>>p[i].x>>p[i].y; int ans = 0; rep(i,0,n-1){ ans += solve(p[i]); } cout<<ans<<endl; } }
|