ABC --128 --A & B & C

AtCoder ABC 128 A&B&C&D AtCoder - 128

I'll be back to solve E & F in the near future.

A - Apple Pie

	private void solveA() {

		out.println((nextInt() * 3 + nextInt()) / 2);
	}

B - Guidebook

--Hold in [] [] of the string, sort in character order by [] [0], and if [] [0] are the same, convert [] [1] to numerical value and sort in descending order

	private void solveB() {
		int n = nextInt();
		String[][] s = new String[n][3];

		for (int i = 0; i < n; i++) {
			s[i][0] = next();
			s[i][1] = next();
			s[i][2] = Integer.toString(i + 1);
		}
		Arrays.sort(s,
				(x, y) -> {
					if (x[0].compareTo(y[0]) < 0) {
						return -1;
					} else if (x[0].compareTo(y[0]) > 0) {
						return 1;
					} else {
						return -Integer.compare(Integer.parseInt(x[1]), Integer.parseInt(y[1]));
					}
				});

		for (int i = 0; i < s.length; i++) {
			out.println(s[i][2]);
		}
	}

C - Switches

--Full search using bit that has become possible to write gradually

--Switches 1-5, the number of switches that must be ON \ Switch number

Light bulb number\Switch number 1 2 3 4 5
1 0
2 1

--For light bulb number 1, the switches that can be used are 1,2,5, and even numbers of 1,2,5 (two in this example) must be ON. ――It is NG that all 1,2,5 are ON, and ON / OFF of 3,4 is irrelevant. --For bulb number 2, the switches that can be used are 2,3, and an odd number of 2,3 (one in this example) must be ON. ――It is NG that both 2 and 3 are ON, and ON / OFF of 1,4,5 is irrelevant.

So there are as many options as $ 2 ^ {number of switches} $

Specifically, try the following pattern ($ 2 ^ {number of switches} $) Taking output example 3 as an example

pattern\switch 1 2 3 4 5
1 Switch 1 ON
Light bulbs 1 and 2 are off
2 Switch 1,2 ON
Light bulbs 1 and 2 are both ON
3 Switch 1,2,3 ON
Light bulb 1 is on. Light bulb 2 is OFF
xxx Switch 1,5 ON
Light bulb 1 is on. Light bulb 2 is OFF
	private void solveC() {
		int n = nextInt();
		int m = nextInt();
		int[] k = new int[m];

		List<List<Integer>> s = new ArrayList<List<Integer>>();
		for (int i = 0; i < k.length; i++) {
			k[i] = nextInt();
			List<Integer> temp = new ArrayList<Integer>();
			for (int j = 0; j < k[i]; j++) {
				temp.add(nextInt());
			}
			s.add(temp);
		}
		int[] p = IntStream.range(0, m).map(i -> nextInt()).toArray();

		long res = 0;
		for (int i = 0; i < 1 << n; i++) {
			boolean isResult = true;
			for (int j = 0; j < m; j++) {
				//Get the button list for light bulb j
				List<Integer> sList = s.get(j);
				//Is it even or odd that the light bulb j must be on?
				int compareBase = p[j];
				//How many of the buttons required to turn on the light bulb j are ON
				int compare = 0;
				for (Integer buttonNum : sList) {
					/*
					 *Find the ON button in the light bulb j button list
					 * buttonNum - 1 ->Button number(According to the array-1)
					 * (i & (1 << (buttonNum - 1)) ->Is the flag set at the position of the button number?
					 */
					if ((i & (1 << (buttonNum - 1))) >= 1) {
						compare++;
					}
				}
				//Judge the number of odds and odds that the button was ON, and judge whether the requirement of light bulb j is satisfied.
				if (compareBase != compare % 2) {
					isResult = false;
					break;
				}
			}
			if (isResult) {
				//This pattern has all the light bulbs turned on
				res++;
			}

		}

		out.println(res);
	}

D - equeue

--Perform the following 4 operations ―― 1: Take from the left ―― 2: Take from the right ―― 3: Discard your hand and put it on the left ―― 4: Discard your hand and put it on the right ―― 3 and 4 can be done at once at the end of the operation (the idea of throwing away unnecessary things at the end), so perform the following operations in all patterns --From the left, take $ 0-max (n, K) $ times --From the right, take $ 0-min (n, (times taken from k-l)) $ times -$ (Times taken from k-l) $ minutes, left or right from hand --Since it is a discard operation, it can be either left or right. I won't take it after throwing it away -Also, it is worth throwing away things smaller than 0 (throwing away will increase the value of your possession), but if you throw away 0 or more, the value of your possession will decrease, so you do not need to throw away

	private void solveD() {
		int n = nextInt();
		int k = nextInt();
		long[] wk = new long[n];
		for (int i = 0; i < n; i++) {
			wk[i] = nextInt();
		}
		long res = 0;
		//Take as much as you can from the left
		for (int l = 0; l <= k; l++) {
			//Take as much as you can from the right
			for (int r = 0; r <= k; r++) {
				//Break if the number of operations exceeds k
				if (l + r > k) {
					break;
				}

				//Total on hand at the moment
				long now = 0;
				List<Long> s = new ArrayList<Long>();
				int pickCount = 0;
				//Add only the amount obtained from the left side
				for (int i = 0; i < Integer.min(l, n); i++) {
					long tmp = wk[i];
					now += tmp;
					s.add(tmp);
					pickCount++;
				}
				/*
				 *Add only the amount obtained from the right side
				 *I'm playing with max on the right side
				 * 	-Because the number of operations (K) may be larger than N
				 *  -There are two loops, one from the left side and the other from the right side.
				 *If K is greater than N, it may take the same thing
				 *Therefore, the original max acquisition number of r and the acquisition number of l are compared.
				 *   e.g.K>=If N, l Integer.min(l, n)And n is returned.
				 */
				for (int i = n - 1; i > Integer.max(n - 1 - r, Integer.min(l, n)); i--) {
					long tmp = wk[i];
					now += tmp;
					s.add(tmp);
					pickCount++;
				}
				//Arrange them in order you don't need them to throw away the extras
				Collections.sort(s);

				//The number of times you can throw away extra acquisition
				int d = k - pickCount;
				//You can't throw away more than this number of times, so break
				for (int i = 0; i < Integer.min(d, s.size()); i++) {
					//
					//If the value of the gem you took out is not negative, you don't have to throw it away
					if (s.get(i) > 0) {
						break;
					}

					//Throw away negative gems
					now -= s.get(i);
				}
				res = Long.max(res, now);
			}
		}
		out.println(res);
	}

Recommended Posts

ABC --013-A & B & C
ABC --023 --A & B & C
ABC --036-A & B & C
ABC --010 --A & B & C
ABC --028 --A & B & C
ABC --015 --A & B & C
ABC --128 --A & B & C
ABC --012-A & B & C
ABC --018 --A & B & C
ABC --054 --A & B & C
ABC --017 --A & B & C
ABC --029- A & B & C
ABC --022 --A & B & C
ABC --019 --A & B & C
ABC --020 --A & B & C
ABC --030- A & B & C
ABC --127 --A & B & C
ABC --007 --A & B & C
ABC --132- A & B & C
ABC --026 --A & B & C
ABC --014- A & B & C
ABC --016 --A & B & C
ABC --011-A & B & C
ABC --031 --A & B & C
ABC --021 --A & B & C
ABC --025 --A & B & C
ABC --024 --A & B & C
ABC --027 --A & B & C
ABC --080- A & B & C
ABC --129- A & B & C & D
ABC --122 --A & B & C & D
ABC --125- A & B & C & D
ABC --130- A & B & C & D
ABC --126 --A & B & C & D
ABC --134- A & B & C & D & E
ABC --131- A & B & C & D & E
diverta 2019 Programming Contest A & B & C & D
AtCoder Beginner Contest 169 A, B, C with ruby
atcoder ABC113 C problem
ABC093 C --Same Integers
atcoder ABC115 C problem
AtCoder Beginner Contest 170 A, B, C up to ruby
A person writing C ++ tried writing Java
Make a SOAP call in C #
Call a C function from Swift
NLP4J [006-034] 100 language processing knocks with NLP4J # 34 "A B"