Smzzl with Greedy Snake
Problem Description
Smzzl is going to make an AI for Greedy Snake. The game goes on xOy
plane and there is no obstacles in the plane.In this game, the snake takes 1 unit of time to move forward for one
unit of length. It also takes 1 unit of time for the snake to rotate
for 90 degrees. (The snake must rotate for the whole unit of time.)
There is a food in the map initially. After the snake eat each food,
the next food appears. Smzzl certainly want the snake to eat the food as fast as possible, so he need to minimize the time when the snake eat each food. Please output a valid operate sequence. Input The input consists of multiple test cases. The first line contains an integer T (1≤T≤200) – the number of test cases. For each test case: In the first line, there are three integers x,y,d (|x|,|y|≤104,
0≤d≤3). The snake starts on (x,y). d shows the direction of the head
of the snake. (0 for y+, 1 for x+, 2 for y-, 3 for x- )
In the second line, there is an integer n (1≤n≤105), which is the
number of foods.In the next n lines, each contains two integers x,y (|x|,|y|≤104),
which means the next food appears at (x,y).It is guaranteed that any line that connects two foods that appear
adjacently does not parallel to the x-axis or the y-axis.Output For each test case, output the shortest operation sequence.
Output ‘f’ for going forward, ‘c’ for rotating clockwise, ‘u’ for
rotating counterclockwise. Each operation lasts for one unit of time.It can be proved that there is only one operation sequence which meets
the requirements.It is guranteed that the total length of output does not exceed 2×106.
Sample Input
2 0 0 0 2
-1 -1 1 1 0 0 2 5
-1 2 2 4 3 -5 4 -2 5 0 Sample Output ufufuffuff cfcffffcffffcfffffffffufufffffcf
模拟
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, x, y) for(auto i=(x);i<=(y);++i)
#define dep(i, x, y) for(auto i=(x);i>=(y);--i)
#define gcd(a, b) __gcd(a,b)
const long long mod = 1e9 + 7;
const int maxn = 3e6 + 10;
int lowbit(int x) {
return x & -x; }
bool ispow(int n) {
return (n & (n - 1)) == 0; }//O(1) 判断是否是 2^k(2的k次方)
int b[maxn];
int n, k;
struct food {
int x, y;
} a[maxn