JZOJ 【NOIP2016提高A组集训第16场11.15】SJR的直线

题目

Description

Input

Output

Sample Input

6

0 1 0

-5 3 0

-5 -2 25

0 1 -3

0 1 -2

-4 -5 29

Sample Output

10

Data Constraint

题解

题意

给出\(n\)个条直线的解析式,问这些直线能组成多少个三角形

题解

发现直接求解不容易求

想到可以先求出最大数量再减去不合法的

最大数量\(C_n^3\),不合法的有两种

  1. 两条平行线+一条不平行的
  2. 三条平行线

那么可以求出斜率然后按照斜率排序,求出每种相同斜率的个数\(c[i]\),和总共斜率的个数\(t\)

答案就是\(C_n^3-\sum_{i=1}^tC_{c[i]}^2*(n-c[i])+C_{c[i]}^3\)

Code

#include<cstdio>
#include<algorithm>
#define mod 1000000007
using namespace std;
long long n,ans,t,c[300001];
struct node
{
long long x,y,z;
}s[300001];
long long read()
{
long long res=0,fh=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') fh=-1,ch=getchar();
while (ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch-'0'),ch=getchar();
return res*fh;
}
bool cmp(node x,node y)
{
double pd1=x.y?(double)-x.x/x.y:1e100;
double pd2=y.y?(double)-y.x/y.y:1e100;
return pd1<pd2;
}
long long C3(long long x) {return (x*(x-1)*(x-2)/6%mod);}
long long C2(long long x) {return (x*(x-1)/2)%mod;}
int main()
{
freopen("trokuti.in","r",stdin);
freopen("trokuti.out","w",stdout);
n=read();
ans=C3(n);
for (int i=1;i<=n;++i)
s[i].x=read(),s[i].y=read(),s[i].z=read();
sort(s+1,s+n+1,cmp);
int i=1,j=1;
while (i<=n)
{
while (j<=n&&s[i].x*s[j].y==s[i].y*s[j].x) ++j;
c[++t]=j-i;
i=j;
}
for (int i=1;i<=t;++i)
ans=(ans+mod-(C2(c[i])*(n-c[i])%mod)-C3(c[i])+mod)%mod;
printf("%lld\n",ans);
fclose(stdin);
fclose(stdout);
return 0;
}

最新文章

  1. Js函数function基础理解
  2. d3 document
  3. 【Linux】find grep 联合使用 过滤所有子目录、文件
  4. 以管理身份运行cmd
  5. Spring的定时任务配置2(转)
  6. 如何自动拼接 Update语句,仅Update已修改的字段
  7. YII 1.0 发表文章用到的小物件
  8. 【Oracle】控制文件管理
  9. 面试题(php部分)
  10. CTF---密码学入门第二题 我喜欢培根
  11. egg.js 的优缺点
  12. 重设msyql数据库root密码
  13. laravel 记录
  14. -bash: /etc/profile: line 11: syntax error near unexpected token `$&#39;{\r&#39;&#39;报错问题解决
  15. curl模拟访问已经存在的cookie
  16. VMWare 14.1 15 Pro 安装 macOS Mojave 10.14.1系统 遇到的问题解决方案
  17. django多对多中间表详解
  18. js 获取中文的拼音首字母
  19. 【android】关于自己实现adapter后gridview中item无法被选中的解决方法
  20. String的getBytes()方法

热门文章

  1. GXOI2018 滚粗记
  2. 【CF1443E】Long Permutation 题解(排列生成模板)
  3. Python练手项目实例汇总(附源码下载)
  4. mybatis拦截器 修改mybatis返回结果集中的字段的值
  5. php正则匹配整数
  6. Java多线程经典题目(医院挂号)
  7. Firefox威武 尚译威武!
  8. epoll oneshot
  9. &lt;连接器和加载器&gt;——概述连接器和加载器
  10. Ceph中的Copyset概念和使用方法