头像

henrychenOutlook




离线:10天前


最近来访(62)
用户头像
都是你
用户头像
Egbert-Lannister.
用户头像
白夜只
用户头像
shaonianxiaozeng
用户头像
2144141603@qq.com
用户头像
小白小白小白小白小白
用户头像
cony
用户头像
qjtbdh288
用户头像
一塌糊涂
用户头像
純真丁一郎です
用户头像
auraro1
用户头像
Feelme
用户头像
Nefelibata_6
用户头像
笙笙笙笙
用户头像
我是菜狗啊啊啊啊啊
用户头像
songpy
用户头像
人生如戏ba
用户头像
L_722
用户头像
Ker
用户头像
不止步于此


本题为codeforce原题
https://codeforces.com/contest/1747/problem/C

import java.util.*;
import java.io.*;

class Main {
    static PrintWriter pw;

    void solve(int n, int[] a) {
        int min = Arrays.stream(a).min().getAsInt();
        pr(a[0] == min ? "Bob" : "Alice");
    }

    private void run() {
        // read_write_file(); // comment this before submission
        FastScanner fs = new FastScanner();
        int t = fs.nextInt();
        while (t-- > 0) {
            int n = fs.nextInt();
            int[] a = fs.readArray(n);
            solve(n, a);
        }
    }

    private final String INPUT = "input.txt";
    private final String OUTPUT = "output.txt";

    void read_write_file() {
        FileInputStream instream = null;
        PrintStream outstream = null;
        try {
            instream = new FileInputStream(INPUT);
            outstream = new PrintStream(new FileOutputStream(OUTPUT));
            System.setIn(instream);
            System.setOut(outstream);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        pw = new PrintWriter(System.out);
        new Main().run();
        pw.close();
    }

    <T> void pr(T t) {
        pw.println(t);
    }

    class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
    }

    void tr(Object... o) {
        pw.println(Arrays.deepToString(o));
    }
}



import java.util.*;
import java.io.*;

class Main {
    static PrintWriter pw;

    void solve(int n, long[] a) {
        for (long x : a) {
            int sq = (int) Math.sqrt(x);
            if ((long) sq * sq != x) {
                pr("NO");
                continue;
            }
            pr(isPrime(sq) ? "YES" : "NO");
        }
    }

    boolean isPrime(int n) {
        if (n <= 1) return false;
        if (n <= 3) return true;
        if (n % 2 == 0 || n % 3 == 0) return false;
        for (int i = 5; i * i <= n; i += 6) {
            if (n % i == 0 || n % (i + 2) == 0) return false;
        }
        return true;
    }

    private void run() {
        // read_write_file(); // comment this before submission
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        long[] a = fs.readArray(n);
        solve(n, a);
    }

    private final String INPUT = "input.txt";
    private final String OUTPUT = "output.txt";

    void read_write_file() {
        FileInputStream instream = null;
        PrintStream outstream = null;
        try {
            instream = new FileInputStream(INPUT);
            outstream = new PrintStream(new FileOutputStream(OUTPUT));
            System.setIn(instream);
            System.setOut(outstream);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        pw = new PrintWriter(System.out);
        new Main().run();
        pw.close();
    }

    <T> void pr(T t) {
        pw.println(t);
    }

    class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        long[] readArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }

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

    void tr(Object... o) {
        pw.println(Arrays.deepToString(o));
    }
}



import java.util.*;
import java.io.*;

class Main {
    static PrintWriter pw;

    private void run() {
        // read_write_file(); // comment this before submission
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        double res = (double) n / 5;
        pr((int) Math.ceil(res));
    }

    private final String INPUT = "input.txt";
    private final String OUTPUT = "output.txt";

    void read_write_file() {
        FileInputStream instream = null;
        PrintStream outstream = null;
        try {
            instream = new FileInputStream(INPUT);
            outstream = new PrintStream(new FileOutputStream(OUTPUT));
            System.setIn(instream);
            System.setOut(outstream);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        pw = new PrintWriter(System.out);
        new Main().run();
        pw.close();
    }

    <T> void pr(T t) {
        pw.println(t);
    }

    class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
    }

    void tr(Object... o) {
        pw.println(Arrays.deepToString(o));
    }
}



import java.util.*;
import java.io.*;

class Main {
    static PrintWriter pw;
    Map<String, Integer> costM;

    void solve(int n, int m, int[][] edges, Set[] forbid) {
        List<List<Integer>> g = initializeGraph(n + 1);
        costM = new HashMap<>();
        packUGCost(g, edges);
        long[] dis = new long[n + 1];
        Arrays.fill(dis, Long.MAX_VALUE);
        Deque<long[]> q = new ArrayDeque<>();
        q.add(new long[]{1L, 0L});
        dis[1] = 0L;
        while (!q.isEmpty()) {
            long[] tmp = q.poll();
            int cur = (int) tmp[0];
            long t = dis[cur];
            Set<Long> se = forbid[cur];
            while (se.contains(t)) {
                t++;
            }
            for (int child : g.get(cur)) {
                int cost = costM.get(cur + " " + child);
                if (dis[child] > t + cost) {
                    dis[child] = t + cost;
                    q.add(new long[]{child, t + cost});
                }
            }
        }
        pr(dis[n] == Long.MAX_VALUE ? -1 : dis[n]);
    }

    List<List<Integer>> initializeGraph(int n) {
        List<List<Integer>> g = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            g.add(new ArrayList<>());
        }
        return g;
    }

    void packUGCost(List<List<Integer>> g, int[][] edges) {
        for (int[] a : edges) {
            g.get(a[0]).add(a[1]);
            g.get(a[1]).add(a[0]);
            costM.put(a[0] + " " + a[1], a[2]);
            costM.put(a[1] + " " + a[0], a[2]);
        }
    }

    private void run() throws IOException {
        // read_write_file(); // comment this before submission
        FastScanner fs = new FastScanner();
        int n = fs.nextInt(), m = fs.nextInt();
        int[][] edges = new int[m][];
        for (int i = 0; i < m; i++) edges[i] = fs.readArray(3);
        Set[] forbid = new Set[n + 1];
        for (int i = 0; i < n; i++) {
            String[] a = fs.nextLine().split(" ");
            forbid[i + 1] = new HashSet();
//            for (String c : a) {
//                forbid[i + 1].add(Integer.parseInt(c));
//            }
            for (int j = 1; j < a.length; j++) {
                forbid[i + 1].add(Long.parseLong(a[j]));
            }
        }
        solve(n, m, edges, forbid);
    }

    private final String INPUT = "input.txt";
    private final String OUTPUT = "output.txt";

    void read_write_file() {
        FileInputStream instream = null;
        PrintStream outstream = null;
        try {
            instream = new FileInputStream(INPUT);
            outstream = new PrintStream(new FileOutputStream(OUTPUT));
            System.setIn(instream);
            System.setOut(outstream);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) throws IOException {
        pw = new PrintWriter(System.out);
        new Main().run();
        pw.close();
    }

    <T> void pr(T t) {
        pw.println(t);
    }

    class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        String nextLine() throws IOException {
            return br.readLine();
        }
    }

    void tr(Object... o) {
        pw.println(Arrays.deepToString(o));
    }
}



import java.util.*;
import java.io.*;

class Main {
    static PrintWriter pw;

    private void run() {
        // read_write_file(); // comment this before submission
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[] a = fs.readArray(n);
        long[] preA = preSum(a);
        Arrays.sort(a);
        long[] preB = preSum(a);
        int m = fs.nextInt();
        for (int i = 0; i < m; i++) {
            int[] e = fs.readArray(3);
            long res;
            if (e[0] == 1) {
                res = subArraySum(preA, e[1] - 1, e[2] - 1);
            } else {
                res = subArraySum(preB, e[1] - 1, e[2] - 1);
            }
            pr(res);
        }
    }

    long[] preSum(int[] a) {
        int n = a.length;
        long[] pre = new long[n + 1];
        for (int i = 0; i < n; i++) pre[i + 1] = pre[i] + a[i];
        return pre;
    }

    long subArraySum(long[] a, int l, int r) {
        return a[r + 1] - a[l];
    }

    private final String INPUT = "input.txt";
    private final String OUTPUT = "output.txt";

    void read_write_file() {
        FileInputStream instream = null;
        PrintStream outstream = null;
        try {
            instream = new FileInputStream(INPUT);
            outstream = new PrintStream(new FileOutputStream(OUTPUT));
            System.setIn(instream);
            System.setOut(outstream);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        pw = new PrintWriter(System.out);
        new Main().run();
        pw.close();
    }

    <T> void pr(T t) {
        pw.println(t);
    }

    class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
    }

    void tr(Object... o) {
        pw.println(Arrays.deepToString(o));
    }
}



import java.util.*;
import java.io.*;

class Main {
    static PrintWriter pw;

    void solve(int n, int[][] a) {
        Map<String, Integer> m = counter(a);
        int res = 1;
        for (int occ : m.values()) res = Math.max(res, occ);
        pr(res);
    }

    Map<String, Integer> counter(int[][] a) {
        Map<String, Integer> m = new HashMap<>();
        for (int[] e : a) {
            String ke = e[0] + " " + e[1];
            m.put(ke, m.getOrDefault(ke, 0) + 1);
        }
        return m;
    }

    private void run() {
        // read_write_file(); // comment this before submission
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[][] a = new int[n][];
        for (int i = 0; i < n; i++) a[i] = fs.readArray(2);
        solve(n, a);
    }

    private final String INPUT = "input.txt";
    private final String OUTPUT = "output.txt";

    void read_write_file() {
        FileInputStream instream = null;
        PrintStream outstream = null;
        try {
            instream = new FileInputStream(INPUT);
            outstream = new PrintStream(new FileOutputStream(OUTPUT));
            System.setIn(instream);
            System.setOut(outstream);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        pw = new PrintWriter(System.out);
        new Main().run();
        pw.close();
    }

    <T> void pr(T t) {
        pw.println(t);
    }

    class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
    }

    void tr(Object... o) {
        pw.println(Arrays.deepToString(o));
    }
}



本题和codeforce 96B 一样 https://codeforces.com/problemset/problem/96/B
codeforce 提交结果 https://codeforces.com/problemset/submission/96/171187474

import java.util.*;
import java.io.*;

public class Main {
    static PrintWriter pw;

    void solve(int n) {
        TreeSet<Long> ts = buildSuperLuckyNumber();
        for (long x : ts) {
            if (x >= n) {
                pr(x);
                return;
            }
        }
    }

    TreeSet<Long> buildSuperLuckyNumber() {
        TreeSet<Long> res = new TreeSet<>();
        Deque<Character> cur = new ArrayDeque<>();
        dfs(cur, res);
        return res;
    }

    void dfs(Deque<Character> cur, TreeSet<Long> res) {
        if (cur.size() > 11) return; // max 7777744444
        for (char i = '0'; i <= '9'; i++) {
            cur.add(i);
            if (ok(cur)) {
                if (isEqual(cur)) res.add(appendNumber(cur));
                dfs(cur, res);
            }
            cur.pollLast();
        }
    }

    boolean ok(Deque<Character> q) {
        if (q.size() > 11) return false;
        for (char c : q) {
            if (c != '4' && c != '7') return false;
        }
        return true;
    }

    long appendNumber(Deque<Character> q) {
        String s = "";
        for (char c : q) s += c;
        return Long.parseLong(s);
    }

    boolean isEqual(Deque<Character> cur) {
        int four = 0, seven = 0;
        for (int x : cur) {
            if (x == '4') {
                four++;
            } else {
                seven++;
            }
        }
        return four == seven;
    }

    private void run() {
        // read_write_file(); // comment this before submission
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        solve(n);
    }

    private final String INPUT = "input.txt";
    private final String OUTPUT = "output.txt";

    void read_write_file() {
        FileInputStream instream = null;
        PrintStream outstream = null;
        try {
            instream = new FileInputStream(INPUT);
            outstream = new PrintStream(new FileOutputStream(OUTPUT));
            System.setIn(instream);
            System.setOut(outstream);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        pw = new PrintWriter(System.out);
        new Main().run();
        pw.close();
    }

    <T> void pr(T t) {
        pw.println(t);
    }

    class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
    }

    void tr(Object... o) {
        pw.println(Arrays.deepToString(o));
    }
}




以小数暴力运行test() 会发现注释中的规律 每次以1 2 4 8 16… 的次数pop

所以可以算出每层的[l, r]
1 -> [1, 5]
2 -> [6, 15]
4 -> [16, 35]
8 -> [36, 75]
16 -> [76, 155]
......

找出n在第几层就行

import java.util.*;
import java.io.*;

class Main {
    static PrintWriter pw;

    void solve(int n) {
        if (n == 1) {
            pr('a');
            return;
        }
        char[] a = {'a', 'b', 'c', 'd', 'e'};
        int l = 1;
        for (int i = 0; 1 << i < n; i++) {
            int v = 1 << i, line = v * 5; // v 表示1 2 4 8 16...  line 表示当前层的总数
            int r = l + line - 1;
            int[] range = new int[]{l, r}; // 当前层的range  [1, 5], [6, 15]....
            if (n >= l && n <= r) { // n 在当前层, 计算结果
                double d = (double) (n - l + 1) / v;
                int idx = (int) Math.ceil(d);
                pr(a[idx - 1]);
                break;
            }
            l = r + 1;
        }
    }

    /*
     1 a b c d e
     2 aa bb cc dd ee
     4 aaaa bbbb cccc dddd eeee
     8 aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee
     */
    void test(int n) {
        Deque<Character> q = new ArrayDeque<>();
        q.add('a');
        q.add('b');
        q.add('c');
        q.add('d');
        q.add('e');
        int cnt = 0;
        while (true) {
            char x = q.poll();
            tr(x);
            cnt++;
            if (cnt == n) {
                pr(x);
                break;
            }
            q.add(x);
            q.add(x);
        }
    }

    private void run() {
        // read_write_file(); // comment this before submission
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        solve(n);
    }

    private final String INPUT = "input.txt";
    private final String OUTPUT = "output.txt";

    void read_write_file() {
        FileInputStream instream = null;
        PrintStream outstream = null;
        try {
            instream = new FileInputStream(INPUT);
            outstream = new PrintStream(new FileOutputStream(OUTPUT));
            System.setIn(instream);
            System.setOut(outstream);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        pw = new PrintWriter(System.out);
        new Main().run();
        pw.close();
    }

    <T> void pr(T t) {
        pw.println(t);
    }

    class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
    }

    void tr(Object... o) {
        pw.println(Arrays.deepToString(o));
    }
}



import java.util.*;
import java.io.*;

class Main {
    static PrintWriter pw;

    void solve(int n, char[] s) {
        int[] a = new int[n];
        Arrays.fill(a, 1);
        for (int i = 0; i < s.length; i++) {
            if (s[i] == '>') {
            } else if (s[i] == '<') {
                a[i + 1] = a[i] + 1;
            } else {
                a[i + 1] = a[i];
            }
        }
        for (int i = n - 2; i >= 0; --i) {
            if (s[i] == '>') {
                a[i] = Math.max(a[i], a[i + 1] + 1);
            } else if (s[i] == '<') {
            } else {
                a[i] = a[i + 1];
            }
        }
        outputA(a);
    }

    void outputA(int[] a) {
        for (int e : a) pw.print(e + " ");
        pr("");
    }

    private void run() {
        // read_write_file(); // comment this before submission
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        char[] s = fs.next().toCharArray();
        solve(n, s);
    }

    private final String INPUT = "input.txt";
    private final String OUTPUT = "output.txt";

    void read_write_file() {
        FileInputStream instream = null;
        PrintStream outstream = null;
        try {
            instream = new FileInputStream(INPUT);
            outstream = new PrintStream(new FileOutputStream(OUTPUT));
            System.setIn(instream);
            System.setOut(outstream);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        pw = new PrintWriter(System.out);
        new Main().run();
        pw.close();
    }

    <T> void pr(T t) {
        pw.println(t);
    }

    class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
    }

    void tr(Object... o) {
        pw.println(Arrays.deepToString(o));
    }
}



import java.util.*;
import java.io.*;

class Main {
    static PrintWriter pw;

    private void run() {
        // read_write_file(); // comment this before submission
        FastScanner fs = new FastScanner();
        String s = fs.next(), t = fs.next();
        pr(reverse(s).equals(t) ? "YES" : "NO");
    }

    String reverse(String s) {
        int n = s.length();
        String res = "";
        for (int i = n - 1; i >= 0; i--) res += s.charAt(i);
        return res;
    }

    private final String INPUT = "input.txt";
    private final String OUTPUT = "output.txt";

    void read_write_file() {
        FileInputStream instream = null;
        PrintStream outstream = null;
        try {
            instream = new FileInputStream(INPUT);
            outstream = new PrintStream(new FileOutputStream(OUTPUT));
            System.setIn(instream);
            System.setOut(outstream);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        pw = new PrintWriter(System.out);
        new Main().run();
        pw.close();
    }

    <T> void pr(T t) {
        pw.println(t);
    }

    class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
    }

    void tr(Object... o) {
        pw.println(Arrays.deepToString(o));
    }
}