博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C2. Power Transmission (Hard Edition)(线段相交)
阅读量:4590 次
发布时间:2019-06-09

本文共 2532 字,大约阅读时间需要 8 分钟。

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
40 01 10 31 2
Output
Copy
14
Input
Copy
40 00 20 42 0
Output
Copy
6
Input
Copy
3-1 -11 03 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
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef pair
P;const int maxn=100010;map
,set
>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<
<

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

你可能感兴趣的文章
win10 安装mysql
查看>>
SQL文 Update From 写法
查看>>
pyc文件的本质
查看>>
洛谷 - P2602 - 数字计数 - 数位dp
查看>>
android 环境配置 与 运行错误
查看>>
POJ 2653
查看>>
余承东:未来5年中国大部分智能手机厂商消失
查看>>
Android中个人推崇的数据库使用方式
查看>>
关于H.264 x264 h264 AVC1
查看>>
北戴河之旅
查看>>
search for a range(找出一个数在数组中开始和结束位置)
查看>>
一次Mutex死锁的原因探究
查看>>
Notepad++ - 通过语言格式设置自定义语法高亮颜色
查看>>
日记(16)-20140928
查看>>
IIS的应用程序池优化方法
查看>>
HTML5 虚拟键盘出现挡住输入框的解决办法
查看>>
绿色astah简体中文版6.8
查看>>
(三)Installation
查看>>
函数_命名空间和作用域
查看>>
bash正则
查看>>