AT_arc231_a.Two Dimensional Invader
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are a magic warrior on a two-dimensional plane, initially located at point (0,0).
N events will now occur. In the i-th event (1≤i≤N), one monster appears at point (Xi,Yi), and you choose whether to defeat this monster with a sword or with magic.
- If you choose to defeat the monster with a sword, you move to point (Xi,Yi). This incurs a cost equal to the square of the Euclidean distance between the point where you were located before moving and point (Xi,Yi).
- If you choose to defeat the monster with magic, a cost of Zi is incurred. In this case, you do not move.
Find the minimum total cost eventually required.
What is Euclidean distance? The Euclidean distance between point (a,b) and point (c,d) is defined as (a−c)2+(b−d)2.
Solve T test cases per input file.
你是一名位于二维平面上的魔法战士,初始位置为点 (0,0)。
接下来将发生 N 个事件。在第 i 个事件(1≤i≤N)中,一只怪物出现在点 (Xi,Yi),你需要选择用剑或魔法击败该怪物。
- 若选择用剑击败怪物,则你需移动至点 (Xi,Yi)。此次移动产生的代价等于你移动前所在位置与点 (Xi,Yi) 之间的欧几里得距离的平方。
- 若选择用魔法击败怪物,则产生代价 Zi;此时你无需移动。
求最终所需的最小总代价。
什么是欧几里得距离?点 (a,b) 与点 (c,d) 之间的欧几里得距离定义为 (a−c)2+(b−d)2。
每组输入文件需解决 T 个测试用例。
输入格式
The input is given from Standard Input in the following format. Here, casei (1≤i≤T) denotes the i-th test case.
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N
X1 Y1 Z1
X2 Y2 Z2
⋮
XN YN ZN
输入从标准输入中按以下格式给出。其中,casei(1≤i≤T)表示第 i 个测试用例。
T
case1
case2
⋮
caseT
每个测试用例按以下格式给出:
N
X1 Y1 Z1
X2 Y2 Z2
⋮
XN YN ZN
输出格式
Output T lines. The i-th line (1≤i≤T) should contain the answer for casei.
输出 T 行。第 i 行(1≤i≤T)应包含 casei 的答案。
输入输出样例
输入#1
2 3 0 4 28 2 9 11 4 5 26 7 6 0 96 0 2 54 9 0 36 0 7 81 6 5 91 2 8 71 7 6 40
输出#1
44 231
说明/提示
Sample 1 Explanation:
- For the first test case, it is optimal to choose to defeat the monster with a sword in the first and third events, and to choose to defeat the monster with magic in the second event. Each event proceeds as follows.
- In the first event, you move from point (0,0) to point (0,4). This incurs a cost of 16.
- In the second event, a cost of 11 is incurred.
- In the third event, you move from point (0,4) to point (4,5). This incurs a cost of 17.
- The total cost eventually required is 16+11+17=44.
Constraints
- 1≤T≤10
- 1≤N≤250000
- 0≤Xi<500 (1≤i≤N)
- 0≤Yi<500 (1≤i≤N)
- 1≤Zi≤109 (1≤i≤N)
- The sum of N over the T test cases is at most 250000.
- All input values are integers.
样例 1 解释:
- 对于第一个测试用例,最优策略是在第一场和第三场事件中选择用剑击败怪物,在第二场事件中选择用魔法击败怪物。各事件的具体过程如下:
- 在第一场事件中,你从点 (0,0) 移动到点 (0,4),产生代价 16。
- 在第二场事件中,产生代价 11。
- 在第三场事件中,你从点 (0,4) 移动到点 (4,5),产生代价 17。
- 最终所需的总代价为 16+11+17=44。
约束条件
- 1≤T≤10
- 1≤N≤250000
- 0≤Xi<500(1≤i≤N)
- 0≤Yi<500(1≤i≤N)
- 1≤Zi≤109(1≤i≤N)
- 所有 T 个测试用例的 N 值之和不超过 250000。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?