You are given an array𝑎aof length𝑛n. We define theequalityof the array as the number of indices1≤𝑖≤𝑛−11≤i≤n−1such that𝑎𝑖=𝑎𝑖+1ai=ai+1. We are allowed to do the following operation:
Select two integers𝑖iand𝑥xsuch that1≤𝑖≤𝑛−11≤i≤n−1and1≤𝑥≤1091≤x≤109. Then, set𝑎𝑖aiand𝑎𝑖+1ai+1to be equal to𝑥x.
Find the minimum number of operations needed such that the equality of the array is less than or equal to11.
Input
Each test contains multiple test cases. The first line contains a single integer𝑡t(1≤𝑡≤1041≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer𝑛n(2≤𝑛≤2⋅1052≤n≤2⋅105) — the length of array𝑎a.
The second line of each test case contains𝑛nintegers𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an(1≤𝑎𝑖≤1091≤ai≤109) — elements of the array.
It is guaranteed that the sum of𝑛nover all test cases does not exceed2⋅1052⋅105
Output
For each test case, print the minimum number of operations needed.
배열에서 arr[i] == arr[i + 1] 이 되는 경우가 최대 1회가 되도록 하는 문제입니다.
임의로 x를 골라서 arr[x]와 arr[x + 1]을 내가 원하는 값으로 바꿔주는 작업을 해줄 수 있습니다.
위의 작업을 하는 최소의 경우를 찾으면 됩니다.
예를 들어
1 1 2 5 4 1 1
이런 배열을 받은 경우 결국 양 끝의 2개가 있는 지점에서부터 가운데로 좁혀와서 중복되는 숫자를 없애줘야 최솟값이 됩니다.
Alice가 먼저 숫자 2개 순서를 바꾸고, Bob이 맨뒤에서부터 숫자 하나씩 지웁니다. Alice는 최대한 작은 숫자가 마지막까지 살아있도록 해야합니다. 2자리인 경우에는 걍 뒤에 있는 숫자가 출력됩니다. 3자리 이상인 경우엔 무조건 최소인 숫자가 출력됩니다. -----예-------시-------- ( '/' 이게 뒤에서 자른 거라고 생각하세요.) 132 -> 31 / 2 -> 1 / 3 321 -> 31 / 2 -> 1 / 3 312 -> 21 / 3 -> 1 / 2
아니 A에 코드를 너무 장황하게 짰어요.. 아 짜증나네 A랑 B는 무조건 쉽게 풀린다는 걸 전제하에 두고 문제 풀어야겠습니다. 이게 뭐하자는 건지 다음
a b c 입력해주면
이걸 만족하는 x y z를 구해주면 돼요.
조건에 a < b < c가 있습니다. 1. c가 제일 크니까 z = c 그대로 고정해둡시다. 그리고 y % c 가 b 여야 한대요. c는 b보다 크죠? 2. y = b 그대로 고정해둡시다. a만 남았습니다. x % b = a 이건 만족하는데, c % x = c여야합니다. 그럼 x가 c보단 크면서 b로 나눴을 때 a가 나머지로 나오게 하면 되겠네요. 3. b * c 를 하면 c보다 큰 동시에 b에 나눠떨어집니다. 거기에 + a 하면 끝.
#include <stdio.h>
int main() {
int t;
scanf("%d", &t);
for(int i = 0; i < t; i++) {
long long a,b,c;
scanf("%lld%lld%lld", &a, &b, &c);
a = a + b * c;
printf("%lld %lld %lld\n", a, b, c);
}
}