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 - 115- A&B&C

Posted at

AtCoder ABC 115 A&B&C

AtCoder - 115

A問題

	private static void ABC115_A() {
		Scanner scanner = null;
		int date = 0;

		try {
			scanner = new Scanner(System.in);
			date = scanner.nextInt();

			switch (date) {
			case 22:
				System.out.println("Christmas Eve Eve Eve");
				break;
			case 23:
				System.out.println("Christmas Eve Eve");
				break;
			case 24:
				System.out.println("Christmas Eve");
				break;
			case 25:
				System.out.println("Christmas");
				break;
			default:
				System.out.println("fail!");
				break;
			}

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

B問題

  • ソートして、一番最後(一番高い)ものを$1/2$にする
	private static void ABC115_B() {
		Scanner scanner = null;
		int numItem = 0;

		try {
			scanner = new Scanner(System.in);
			numItem = scanner.nextInt();
			int[] priceArray = new int[numItem];

			for (int i = 0; i < numItem; i++) {
				priceArray[i] = scanner.nextInt();
			}

			Arrays.sort(priceArray);

			int prices = 0;
			for (int i = 0; i < priceArray.length; i++) {
				if (i != numItem - 1) {
					prices += priceArray[i];
				} else {
					prices += priceArray[i] / 2;
				}

			}

			System.out.println(prices);

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

C問題

  • いくつか選択して飾り付けるので、選択する木は何でもよい
  • 木を高さでソートして、N本連続で選択し、最小と最大を比較する
  • N本連続するのを全てのパターン試せばよい
	private static void ABC115_C() {
		Scanner scanner = null;
		int totalTreeNum = 0;
		int selectedTreeNum = 0;

		try {
			scanner = new Scanner(System.in);
			totalTreeNum = scanner.nextInt();
			selectedTreeNum = scanner.nextInt();

			int[] treeTehightList = new int[totalTreeNum];

			for (int i = 0; i < totalTreeNum; i++) {
				treeTehightList[i] = scanner.nextInt();
			}

			Arrays.sort(treeTehightList);

			//			int[] sabunList = new int[treeTehightList.length - 1];

			//			for (int i = 0; i < sabunList.length; i++) {
			//				sabunList[i] = treeTehightList[i + 1] - treeTehightList[i];
			//			}
			int minDiff = 0;
			for (int i = 0; i < treeTehightList.length - (selectedTreeNum - 1); i++) {
				if (i == 0) {
					minDiff = treeTehightList[i + selectedTreeNum - 1] - treeTehightList[i];
				}
				if (minDiff > treeTehightList[i + selectedTreeNum - 1] - treeTehightList[i]) {
					minDiff = treeTehightList[i + selectedTreeNum - 1] - treeTehightList[i];
				}

			}
			System.out.println(minDiff);

		} 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?