C2. Power Transmission (Hard Edition)(线段相交)

This problem is same as the previous one, but has larger constraints.

It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic.

At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates (??,??)

. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire.

Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem?

Input

The first line contains a single integer ?

(2?1000

) — the number of electric poles.

Each of the following ?

lines contains two integers ??, ?? (104??,??104

) — the coordinates of the poles.

It is guaranteed that all of these ?

points are distinct.

Output

Print a single integer — the number of pairs of wires that are intersecting.

Examples
Input
Copy
4
0 0
1 1
0 3
1 2
Output
Copy
14
Input
Copy
4
0 0
0 2
0 4
2 0
Output
Copy
6
Input
Copy
3
-1 -1
1 0
3 1
Output
Copy
0
Note

In the first example:

In the second example:

Note that the three poles (0,0)

, (0,2) and (0,4)

are connected by a single wire.

In the third example:

#include<iostream>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int maxn=100010;
map<pair<int,int>,set<int> >mp;
ll cnt,ans,n;
int x[maxn],y[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>x[i]>>y[i];
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int a=x[i]-x[j],b=y[i]-y[j],c=x[i]*y[j]-x[j]*y[i];
            int g=__gcd(a,b);
            a/=g;b/=g;c/=g;
            P p=make_pair(a,b);
            if(mp[p].find(c)==mp[p].end()){
                cnt++;
                mp[p].insert(c);
                ans+=cnt-mp[p].size();
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

转载于:https://www.cnblogs.com/cherish-lin/p/11066353.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值