Codeforces Round #497 (Div. 2)

  • Codeforces Round #497 (Div. 2)(java)
    • A Romaji
    • B Turn the Rectangles
    • C Reorder the Array

Codeforces Round #497 (Div. 2)(java)

刷题笔记
这次区分度不太好,DIV2只有前20人能做出一道D或者E,后面几千人全都是三题…..

A Romaji

problem1008A
题意大致为要求除a,e,i,o,u五个元音字母外的所有字母(n除外)后都必须跟一个元音字母,符合输出YES,不符合输出NO

public class ARomaji {
    private static char[] vowel = new char[]{'a', 'i', 'u', 'e', 'o'};
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        System.out.println(isRomaji(s)?"YES":"NO");
    }

    public static boolean isRomaji(String s) {
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (!isVowel(c) && c != 'n') {
                if (i + 1 >= s.length() || !isVowel(s.charAt(i + 1))) {
                    return false;
                }
            }
        }
        return true;
    }

    public static boolean isVowel(char x) {
        for (int i = 0; i < vowel.length; i++) {
            if (vowel[i] == x) {
                return true;
            }
        }
        return false;
    }

}

B Turn the Rectangles

problem1008B
给一堆矩形,可以对矩形进行翻转,问矩形是否能变成高度非递增的序列.

public class BTurntheRectangles {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        boolean flag = true;
        int[] arr = new int[n];
        int x, y, max, min;
        for (int i = 0; i < n; i++) {
            x = scan.nextInt();
            y = scan.nextInt();
            if (!flag) continue;
            if (i == 0) {
                arr[i] = Math.max(x, y);
            } else {
                max = Math.max(x, y);
                min = Math.min(x, y);
                if (min > arr[i - 1]) {
                    flag = false;
                } else {
                    arr[i] = max <= arr[i - 1] ? max : min;
                }
            }
        }
        System.out.println(flag?"YES":"NO");
    }
}

C Reorder the Array

problem1007A
题目本身较为简单,就是英文不好的读题容易出错.起初把描述中的[10,20,30,40]变为[20,10,40,30]当成样例了.然后与样例一反复来回看,以为题目描述错了,但又迟迟不见题目纠正信息.然后仔仔细细读了题后发现,描述中并没有说[20,10,40,30]是最优解,尬死了

我的做法是记录两个下标i,j初始为0,对于每个i,不断增加j的值找到个大于i的值,这个时候就可以置换掉i(计数++),然后可以找下个i的j

public class CReorderTheArray {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }
        Arrays.sort(arr);
        int count = 0;
        for (int i = 0, j = 0; i < arr.length; i++) {
            while (j < arr.length) {
                if (arr[j] > arr[i]) {
                    count++;
                    j++;
                    break;
                }
                j++;
            }
            if (j == arr.length) {
                break;
            }
        }
        System.out.println(count);
    }
}

你可能感兴趣的:(Codeforces,acm)