L


私信TA

用户名:1302759659

访问量:2151

签 名:

等  级
排  名 859
经  验 3477
参赛次数 0
文章发表 13
年  龄 17
在职情况 学生
学  校 广西英华国际职业学院
专  业 软件技术

  自我简介:

解题思路:  把1-n的值初始化大一点 保存最大最小值跟着变化最后根据下标排个序就行了


参考代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;

class Jgt {
    public long index, key;

    public Jgt(long index, long key) {
        this.index = index;
        this.key = key;
    }
}

public class Main {
    public static void main(String[] args) {
        Input sc = new Input(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Jgt[] a = new Jgt[n + 1];
        long Lindex = 999999999L;
        long Rindex = -1;
        for (int i = 1; i <= n; i++) {
            a[i] = new Jgt(i, i + 10000000);
            Lindex = Math.min(a[i].key, Lindex);
            Rindex = Math.max(a[i].key, Rindex);
        }
        while (m-- > 0) {
            char c = sc.next().charAt(0);
            int x = sc.nextInt();
            if (c == 'L') {
                a[x].key = Lindex - 1;
                Lindex = a[x].key;
            } else {
                a[x].key = Rindex + 1;
                Rindex = a[x].key;
            }
        }

        Arrays.sort(a, 1, n + 1, (o1, o2) -> (int) (o1.key - o2.key));
        for (int i = 1; i <= n; i++) {
            System.out.print(a[i].index + " ");
        }
    }

    static class Input {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public Input(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            String str = null;
            try {
                str = reader.readLine();
            } catch (IOException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public Double nextDouble() {
            return Double.parseDouble(next());
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}


 

0.0分

4 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区