题目要求
P1086题目链接
这个题是强行规定的贪心,就很简单啦。只需要排个序,逐一尝试即可。
每次都要试图跳到下一个格子,试一试过去消耗的距离加上从新位置到跳回路边的距离和会不会超出限制。
是这样的,如果当前点能跳回去,那跳回去的距离绝对小于等于尝试下一个点的距离。当且仅当下一个点在当前点直线返回出发位置的直线上时等号成立。
所以,策略就是,尽量尝试,行就继续,不行就回滚并结束。
为了防止地图大,在读的时候T掉,所以开BufferedReader。
AC代码(Java语言描述)import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class Main {
private static class Point {
int x;
int y;
Integer value;
Point(int x, int y, int value) {
this.x = x;
this.y = y;
this.value = value;
}
}
public static void main(String[] args) throws IOException {
List list = new ArrayList();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] first_line = reader.readLine().split("\\s+");
int m = Integer.parseInt(first_line[0]);
int n = Integer.parseInt(first_line[1]);
int time = Integer.parseInt(first_line[2]);
for (int i = 1; i
关注
打赏
热门博文
- 【Linux】Ubuntu20.04安装和卸载MySQL8
- 【Linux】Ubuntu 20.04 报错 curl: (23) Failure writing output to destination 的解决方法
- 【Java】JUnit 4.13.2 警告 ‘assertEquals(double, double)‘ is deprecated 的解决方法
- 【JavaScript】处理 @parcel/transformer-js: Browser scripts cannot have imports or exports.
- 【Python】处理TypeError: Plain typing.NoReturn is not valid as type argument
- 【Python】Matplotlib可视化50例
- 【C语言】C语言修改MySQL数据库
- 【Java】从默认包导入类和对象报错的解决方法
- 【Java】panel.getGraphics()报错空指针异常的解决方法
- 【Java】IDEA编译Java项目报错 java: 找不到符号 的解决方法