A1126 | [COCI-2007_2008-contest5]#2 BARICA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Barica is an unusual frog. She lives in a pond where N plants float on the surface of the water. The plants are numbered 1 through N. When viewing from above, the location of each plant is given by a pair of coordinates. What makes Barica unusual is her fear of jumping diagonally and in the negative direction. More precisely, she can jump from a plant at coordinates (x1, y1) to another at coordinates (x2, y2) only if:
• x2 > x1 and y2 = y1, or
• y2 > y1 and x2 = x1 For each plant, we know the number of flies in its immediate vicinity. Barica can use her swift tongue to eat all flies near the plant she is at.
Barica absorbs one energy unit for each fly she eats, and uses K energy units for each jump she makes.
Barica can not make a jump if she doesn't have enough energy units beforehand.
Barica wants to go from plant 1 to plant N and have the largest amount of energy possible after arriving. Barica initially has no energy and must gather energy for her first jump from the flies around plant
1.
Find the sequence of plants Barica should travel to achieve her goal.
• x2 > x1 and y2 = y1, or
• y2 > y1 and x2 = x1 For each plant, we know the number of flies in its immediate vicinity. Barica can use her swift tongue to eat all flies near the plant she is at.
Barica absorbs one energy unit for each fly she eats, and uses K energy units for each jump she makes.
Barica can not make a jump if she doesn't have enough energy units beforehand.
Barica wants to go from plant 1 to plant N and have the largest amount of energy possible after arriving. Barica initially has no energy and must gather energy for her first jump from the flies around plant
1.
Find the sequence of plants Barica should travel to achieve her goal.
输入格式
The first line of input contains two integers N and K (2 ≤ N ≤ 300 000, 1 ≤ K ≤ 1000) separated by a space.
Each of the following N lines contains three integers X, Y and F (0 ≤ X, Y ≤ 100 000, 0 ≤ F ≤ 1000)
separated by spaces, meaning that there is a plant at coordinates (X, Y) with F flies around it.
The first plant in the input is plant 1, the second is plant 2 etc.
No two plants will share the same pair of coordinates.
Note: The input data will guarantee that a sequence of jumps, although not necessarily unique, will always exist.
Each of the following N lines contains three integers X, Y and F (0 ≤ X, Y ≤ 100 000, 0 ≤ F ≤ 1000)
separated by spaces, meaning that there is a plant at coordinates (X, Y) with F flies around it.
The first plant in the input is plant 1, the second is plant 2 etc.
No two plants will share the same pair of coordinates.
Note: The input data will guarantee that a sequence of jumps, although not necessarily unique, will always exist.
输出格式
Output the final energy level on the first line.
Output an integer L, the number of plants Barica should travel, including plants 1 and N.
On the following L lines, output the sequence of plants Barica should travel.
Output an integer L, the number of plants Barica should travel, including plants 1 and N.
On the following L lines, output the sequence of plants Barica should travel.
输入输出样例
输入 #1
6 5 1 1 5 2 1 5 1 2 4 2 3 5 3 2 30 3 3 5
输出 #1
5 4 1 1 2 1 2 3 3 3
输入 #2
8 10 1 1 15 2 2 30 1 2 8 2 1 7 3 2 8 2 3 7 4 2 100 3 3 15
输出 #2
36 5 1 1 1 2 2 2 3 2 3 3
输入 #3
9 5 5 5 10 6 5 2 7 5 1 5 6 2 6 6 6 7 6 2 5 7 1 6 7 2 7 7 1
输出 #3
2 3 5 5 7 5 7 7
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted