QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 1024 MB Total points: 15

#5757. 作物三角形

Statistics

一些恶作剧者看了太多的探索频道(Discovery Channel),现在他们想在夜间建造一个麦田三角形。他们想在一个从上方看去像均匀间隔网格的大型农田中建造它。田里种着一些树。 每棵树都位于两条网格线的交点(网格点)上。 恶作剧者希望他们的麦田三角形的顶点位于这些树上。 此外,为了让他们的麦田三角形更有趣,他们希望该三角形的中心也位于某个网格点上。 我们提醒你,如果一个三角形的顶点为 $(x_1, y_1)$,$(x_2, y_2)$ 和 $(x_3, y_3)$,那么该三角形的中心坐标为 $((x_1 + x_2 + x_3) / 3, (y_1 + y_2 + y_3) / 3)$。

你将获得一组具有整数坐标的点,表示网格上所有树的位置。 你需要计算有多少个由该点集中的不同顶点组成的三角形,其中心也是一个网格点(即中心坐标为整数)。

如果一个三角形的面积为 0,我们仍然将其视为一个有效的三角形。

输入格式

输入的第一行给出了测试用例的数量 $N$。 接下来是 $N$ 个测试用例。每个测试用例包含一行,其中包含由空格分隔的整数 $n$,$A$,$B$,$C$,$D$,$x_0$,$y_0$ 和 $M$。$n$ 是输入集合中树的数量。 使用数字 $n$,$A$,$B$,$C$,$D$,$x_0$,$y_0$ 和 $M$,以下伪代码将打印输入集合中树的坐标。 mod 表示取余运算。

参数的选择将确保输入树的集合中不会有重复项。

X = x0, Y = y0
print X, Y
for i = 1 to n-1
    X = (A * X + B) mod M
    Y = (C * Y + D) mod M
    print X, Y

输出格式

对于每个测试用例,输出一行,包含 "Case #$X$: ",其中 $X$ 是测试用例编号(从 1 开始)。 后面应跟一个整数,表示由 3 个不同的树组成且中心为网格点的三角形数量。

数据范围

$1 \le N \le 10$

$0 \le A, B, C, D, x_0, y_0 \le 10^9$

$1 \le M \le 10^9$

小数据集(测试集 1 - 可见;5 分)

$3 \le n \le 100$

大数据集(测试集 2 - 隐藏;10 分)

$3 \le n \le 100000$

样例

样例输入 1

2
4 10 7 1 2 0 1 20
6 2 0 2 1 1 2 11

样例输出 1

Case #1: 1
Case #2: 2

说明

在第一个测试用例中,生成的输入集合中的 4 棵树分别是 (0, 1), (7, 3), (17, 5), (17, 7)。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.