35分,其余全超时
查看原帖
35分,其余全超时
749028
QAQ5楼主2024/12/30 14:49
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        People[] peoples;
        Command[] commands;
        {
            Scanner scanner = new Scanner(System.in);
            String[] two = scanner.nextLine().split(" ");
            int peopleNum = Integer.parseInt(two[0]), commandNum = Integer.parseInt(two[1]);
            peoples = new People[peopleNum];
            commands = new Command[commandNum];
            for (int count = 0; count < peopleNum; count++) {
                two = scanner.nextLine().split(" ");
                int faceNum = Integer.parseInt(two[0]);
                String career = two[1];
                Face face = null;
                if (faceNum == 0) face = Face.in;
                else if (faceNum == 1) face = Face.out;
                peoples[count] = new People(face, career);
            }
            for (int count = 0; count < commandNum; count++) {
                two = scanner.nextLine().split(" ");
                int dirNum = Integer.parseInt(two[0]), stepNum = Integer.parseInt(two[1]);
                Direction direction = null;
                if (dirNum == 0) direction = Direction.left;
                else if (dirNum == 1) direction = Direction.right;
                commands[count] = new Command(direction, stepNum);
            }
        }
//        System.out.println(Arrays.toString(peoples));
//        System.out.println(Arrays.toString(commands));
        Circle circle = new Circle(peoples);
        for (Command command : commands) {
            People currentPeople = circle.get();
//            System.out.println("当前人:" + currentPeople);
//            System.out.println("命令:" + command);
            if (currentPeople.face == Face.out) {//晕了,乱搞算了
                if (command.direction == Direction.left)
                    circle.toRight(command.step);
                else if (command.direction == Direction.right)
                    circle.toLeft(command.step);
            } else if (currentPeople.face == Face.in) {
                if (command.direction == Direction.left)
                    circle.toLeft(command.step);
                else if (command.direction == Direction.right)
                    circle.toRight(command.step);
            }
//            System.out.println("命令后人:" + circle.get());
//            System.out.println();
        }
        System.out.println(circle.get().career);
    }
}

class Circle {
    People[] data;
    int point = 0;

    Circle(People[] peoples) {
        data = peoples;
    }

    People get() {
        return data[point];
    }

    void toLeft(int step) {
        int to = point - step;
        while (to < 0) {
            to = data.length + to;
        }
        point = to;
    }

    void toRight(int step) {
        int to = point + step;
        while (data.length < to) {
            to -= data.length;
        }
        point = to;
    }
}

class Command {
    Direction direction;
    int step;

    Command(Direction direction, int step) {
        this.direction = direction;
        this.step = step;
    }

    @Override
    public String toString() {
        return "方向:" + direction + ",步数:" + step;
    }
}

enum Direction {
    left, right;

    @Override
    public String toString() {
        return switch (this) {
            case left -> "左";
            case right -> "右";
        };
    }
}

class People {
    Face face;
    String career;

    People(Face face, String career) {
        this.face = face;
        this.career = career;
    }

    @Override
    public String toString() {
        return "朝向:" + face + ",职业:" + career;
    }
}

enum Face {
    in, out;

    @Override
    public String toString() {
        return switch (this) {
            case in -> "内";
            case out -> "外";
        };
    }
}

2024/12/30 14:49
加载中...