Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

P7676 [COCI2013-2014#5] TROKUTI

P7676 [COCI2013-2014#5] TROKUTI

任意三条斜率不同的点可以组成三角形。将斜率离散化后直接统计即可。

注意判断斜率不存在。

查看代码
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
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
template <class Type>
void read(Type &x)
{
char c;
bool flag = false;
while ((c = getchar()) < '0' || c > '9')
c == '-' && (flag = true);
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 3) + (x << 1) + c - '0';
if (flag) x = ~x + 1;
}
typedef long long LL;
template <class Type, class ...rest>
void read(Type &x, rest &...y) { read(x), read(y...); }
template <class Type>
void write(Type x)
{
if (x < 0) putchar('-'), x = ~x + 1;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
const int N = 3e5 + 10, mod = 1e9 + 7;
void adj (int &x) { x += x >> 31 & mod; }
int n, m, w[N];
struct Line
{
int a, b;
bool operator < (const Line &_) const { return (double)a / b < (double)_.a / _.b; }
bool operator == (const Line &_) const { return (LL)a * _.b == (LL)b * _.a; }
};
int main ()
{
read(n);
vector <Line> v;
for (int i = 1, a, b; i <= n; ++i)
{
read(a, b), scanf("%*d");
if (b) v.push_back((Line){a, b});
else ++w[0];
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); ++i)
++w[i && v[i] == v[i - 1] ? m : ++m];
int res = 0;
for (int i = 0, s = 0, t = 0; i <= m; ++i)
{
adj(res += (LL)s * w[i] % mod - mod);
adj(s += (LL)t * w[i] % mod - mod);
adj(t += w[i] - mod);
}
write(res);
return 0;
}