0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ABC - 110- A&B&C

Posted at

AtCoder ABC 110A&B&C

AtCoder - 110

A問題

  • 入力値をソートして
    • 最大値を $*10$
    • 真ん中の値と一番小さい値を足す
	private void solveA() {
		Scanner scanner = null;

		try {
			scanner = new Scanner(System.in);
			int[] line = new int[3];
			for (int i = 0; i < 3; i++) {
				line[i] = scanner.nextInt();
			}

			Arrays.sort(line);

			int result = line[2] * 10 + line[1] + line[0];

			System.out.println(result);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

B問題

  • $X<Z≤Y$
    • Xより大きくY以下
  • $x_1,x_2,...,x_N<Z$
    • xの全都市より大きい(入力値をソートした最大値より大きい)
  • $y_1,y_2,...,y_M≥Z$
    • yの全都市以下(入力値をソートした最小値以下)
  • 上記を満たすZは
    • ソートした$x$の最大値に$+1$ した値(より大きい)が、ソートした$y$の最小値以下
    • ソートした$x$の最大値に$+1$ した値(より大きい)が、$X<Z≤Y$
	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numM = 0;
		int numX = 0;
		int numY = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numM = scanner.nextInt();
			numX = scanner.nextInt();
			numY = scanner.nextInt();

			int[] targetX = new int[numN];
			for (int i = 0; i < numN; i++) {
				targetX[i] = scanner.nextInt();
			}

			Arrays.sort(targetX);

			int[] targetY = new int[numM];
			for (int i = 0; i < numM; i++) {
				targetY[i] = scanner.nextInt();
			}

			Arrays.sort(targetY);

			int numZ = targetX[numN - 1] + 1;

			if (numX < numZ && numZ <= numY && targetY[0] >= numZ) {
				System.out.println("No War");
			} else {
				System.out.println("War");
			}

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

C問題

例1:
C1: azzel
C2: apple

  • 文字順は変更できない

  • 全ての文字が$C1_i ; -> ; C2_i$に変換可能

  • 文字列Sに含まれる全ての文字Aが、文字Bに変換可能か否か

    • 全ての文字A→文字Bが成り立つ必要がある
      • 文字A→文字Cが出現したらNG
        • C1->C2がe->lとなるなら、C1->C2がe->C等が発生してはいけない
  • 文字A→文字Bは文字B→文字Aも成り立つ必要がある

    • 文字B→文字Cが出現したらNG
      • C1->C2がe->lとなるなら、C2->C1もl->eとなる必要がある
      • C1->C2がe->lなのに、C2->C1がl->aとなるばあいは変換できない
	private void solveC() {
		Scanner scanner = null;
		String lineS = "";
		String lineT = "";

		try {
			scanner = new Scanner(System.in);
			lineS = scanner.nextLine();
			lineT = scanner.nextLine();

			char[] wkS = lineS.toCharArray();
			char[] wkT = lineT.toCharArray();

			if (wkS.length != wkT.length) {
				System.out.println("No");
				return;
			}

			//文字列Sに含まれる全ての文字Aが、文字Bに変換可能か否か。全ての文字A→文字Bが成り立つ必要がある。文字A→文字Cが出現したらNG
			Map<Character, Character> mapS = new HashMap<Character, Character>();
			for (int i = 0; i < wkS.length; i++) {
				char wS = wkS[i];
				char wT = wkT[i];
				if (mapS.get(wS) == null) {
					mapS.put(wS, wT);
				} else if (!mapS.get(wS).equals(wT)) {
					System.out.println("No");
					return;
				}
			}

			Map<Character, Character> wkMap = new HashMap<Character, Character>();

			//文字A→文字Bは文字B→文字Aも成り立つ必要がある。文字B→文字Cが出現したらNG
			for (Iterator<Entry<Character, Character>> iterator = mapS.entrySet().iterator(); iterator.hasNext();) {

				Entry<Character, Character> key = iterator.next();
				if (wkMap.get(key.getValue()) == null) {
					wkMap.put(key.getValue(), key.getKey());
				} else {
					Character wkChara = wkMap.get(key.getValue());
					if (!wkChara.equals(key.getKey())) {
						System.out.println("No");
						return;
					}
				}
			}

			System.out.println("Yes");
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?