8.10 第七场 Smzzl with Greedy Snake

8.10 第七场 Smzzl with Greedy Snake

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 920 Accepted Submission(s): 527

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 😆

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<iostream>
#include <cstdio>

using namespace std;

int main() {
    int t;
    int x, y, d, n, a, b;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d%d", &x, &y, &d);
        scanf("%d", &n);
        while (n--) {
            scanf("%d%d", &a, &b);
            if (a > x && b > y) {
                if (d == 2 || d == 1) {
                    if (d == 2)
                        printf("u");
                    for (int i = 0; i < a - x; ++i) {
                        printf("f");
                    }
                    printf("u");
                    for (int i = 0; i < b - y; ++i) {
                        printf("f");
                    }
                    d = 0;
                } else {
                    if (d == 3)
                        printf("c");
                    for (int i = 0; i < b - y; ++i) {
                        printf("f");
                    }
                    printf("c");
                    for (int i = 0; i < a - x; ++i) {
                        printf("f");
                    }
                    d = 1;
                }

            } else if (a > x && b < y) {
                if (d == 0 || d == 1) {
                    if (d == 0)
                        printf("c");
                    for (int i = 0; i < a - x; ++i) {
                        printf("f");
                    }
                    printf("c");
                    for (int i = 0; i < y - b; ++i) {
                        printf("f");
                    }
                    d = 2;
                } else {
                    if (d == 3)
                        printf("u");
                    for (int i = 0; i < y - b; ++i) {
                        printf("f");
                    }
                    printf("u");
                    for (int i = 0; i < a - x; ++i) {
                        printf("f");
                    }
                    d = 1;
                }
            } else if (a < x && b > y) {
                if (d == 2 || d == 3) {
                    if (d == 2)
                        printf("c");
                    for (int i = 0; i < x - a; ++i) {
                        printf("f");
                    }
                    printf("c");
                    for (int i = 0; i < b - y; ++i) {
                        printf("f");
                    }
                    d = 0;
                } else {
                    if (d == 1)
                        printf("u");
                    for (int i = 0; i < b - y; ++i) {
                        printf("f");
                    }
                    printf("u");
                    for (int i = 0; i < x - a; ++i) {
                        printf("f");
                    }
                    d = 3;
                }
            } else {
                if (d == 0 || d == 3) {
                    if (d == 0)
                        printf("u");
                    for (int i = 0; i < x - a; ++i) {
                        printf("f");
                    }
                    printf("u");
                    for (int i = 0; i < y - b; ++i) {
                        printf("f");
                    }
                    d = 2;
                } else {
                    if (d == 1)
                        printf("c");
                    for (int i = 0; i < y - b; ++i) {
                        printf("f");
                    }
                    printf("c");
                    for (int i = 0; i < x - a; ++i) {
                        printf("f");
                    }
                    d = 3;
                }
            }
            x = a, y = b;
        }
        printf("\n");
    }
    return 0;
}
posted @   嘿,抬头!  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示