[NOIP2016 Improved Group A Training Session 16, 11.15] SJR’s straight line [Konjak’s small problem solution]

Description

Insert picture description here

InputInsert picture description here

Sample Input

6
0 1 0
-5 3 0
-5 -2 25
0 1 -3
0 1 -2
-4 -5 29

OutputInsert picture description here

Sample Output

10

Topic

Give you a bunch of straight lines and find how many triangles they can construct.

Ideas

See the slope formula given by the title:
A i ∗ x + B i ∗ y + ci = 0 Ai*x+Bi*y+ci=0To ix+B iY+c i=After 0
transfer:
A i ∗ x + ci = − B i Ai * x + ci = -BiTo ix+c i=
Take the opposite of both sides of B i and divideB i BiB i :
y = - ai / bi - ci / biy = -ai / bi-ci / biY=A i / b iC i / B i
why i-th Article straight线斜rate currency and:- Ai / Bi -Ai / BiA i / b i
We can also know that an illegal plan is the number of plans where two lines are parallel or three lines are parallel. If two lines are parallel to each other, the slope is the same.
The total number of plans is:C (n, 3) C(n,3)C(n,3 )
So the answer isC (n, 3) C(n, 3)C(n,3 ) Subtract the number of illegal schemes.

CODE

//L.E.M.T专用水印
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long f[500005][10],sum,mo=1e9+7;
long double g[500005];
int n,a,b,c,s;
int main() {
    
    
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d%d",&a,&b,&c),g[i]=(1.0*a)/(1.0*b);//求斜率
	f[1][1]=1;
	for (int i=2;i<=n+1;i++) for (int j=1;j<=5;j++) f[i][j]=(f[i-1][j]+f[i-1][j-1]+mo)%mo;//杨辉三角预处理组合数
	sort(g+1,g+1+n),s=1;
	for (int i=2;i<=n;i++)
		if (g[i]==g[i-1]) s++;
		else sum=(sum+(f[s+1][3]*(n-s)+mo)%mo+(f[s+1][4]+mo)%mo+mo)%mo,s=1;//sum为不合法方案数
	sum=(sum+(f[s+1][3]*(n-s)+mo)%mo+(f[s+1][4]+mo)%mo+mo)%mo;
	printf("%lld",(f[n+1][4]-sum+mo)%mo);
}

Guess you like

Origin blog.csdn.net/qq_49972640/article/details/109262340