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

Posted at

AtCoder ABC 108 A&B&C

AtCoder - 108

A問題

  • ループしてカウントしたパターン

	private void solveA() {
		Scanner scanner = null;
		int numK = 0;
		int eqaC = 0;
		int oddC = 0;

		try {
			scanner = new Scanner(System.in);
			numK = scanner.nextInt();
			for (int i = 1; i <= numK; i++) {
				if (i % 2 == 0) {
					eqaC++;
				} else {
					oddC++;
				}
			}

			System.out.println(eqaC * oddC);

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

A問題:2

  • 数値K
    • 奇数の個数:$(K+1)/2$
    • 偶数の個数:$K/2$
	private void solveA2() {
		Scanner scanner = null;
		int numK = 0;

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

			System.out.println((numK / 2) * ((numK + 1) / 2));

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

B問題

  • 頂点が反時計回りの長方形
    • 紙に実際に書いてみると頂点の算出は簡単(頭の中だけだとチョイ無理)
	private void solveB() {
		Scanner scanner = null;
		int x1 = 0;
		int y1 = 0;
		int x2 = 0;
		int y2 = 0;

		try {
			scanner = new Scanner(System.in);
			x1 = scanner.nextInt();
			y1 = scanner.nextInt();
			x2 = scanner.nextInt();
			y2 = scanner.nextInt();

			int x3 = x2 - (y2 - y1);
			int y3 = y2 + (x2 - x1);
			int x4 = x3 - (y3 - y2);
			int y4 = y3 + (x3 - x2);

			System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);

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

C問題

上手くまとめられないので思考過程を記述するのを放棄する

参考:これらのサイトのお世話になりました
ARC102[Triangular Relationship]
ABC108: C - Triangular Relationship
AtCoder ARC 102 C - Triangular Relationship (300 点)

private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;

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

			long cnt = 0;

			if (numK % 2 != 0) {
				long numCount = 0;
				for (int i = 1; i <= numN; i++) {
					if (i % numK == 0) {
						numCount++;
					}
				}
				cnt = (long) Math.pow(numCount, 3);
			} else {
				long numCount = 0;
				long numCount2 = 0;
				for (int i = 1; i <= numN; i++) {
					if (i % numK - numK / 2 == 0) {
						numCount++;
						//						System.out.println(i + " : 0");
					} else if (i % numK == 0) {
						numCount2++;
						//						System.out.println(i + " : 1");
					}
				}
				cnt = (long) Math.pow(numCount, 3) + (long) Math.pow(numCount2, 3);
			}

			System.out.println(cnt);

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