티스토리 뷰
Dashboard - Codeforces Global Round 17 - Codeforces
Dashboard - Codeforces Global Round 17 - Codeforces
codeforces.com
!!!! 모든 답은 제 풀이일 뿐 정해가 아닐 수 있습니다 !!!!
A. Anti Light's Cell Guessing
Problem - A - Codeforces
codeforces.com
문제
x,y 그리드에서 컴퓨터가 랜덤하게 한칸의 셀을 지정한다. 여기서 임의의 셀을 지정하면 컴퓨터가 지정한 셀과의 맨해튼 거리를 알려줄 때, 지정한 칸에 상관없이 확실하게 컴퓨터가 지정한 셀을 알 수 있는 최소 쿼리의 수를 출력하는 문제
풀이
1x1은 답이0, 1xn OR nx1은 답이 1, 이외에는 답이 2이다.
코드
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int T;
cin >> T;
while (T--) {
long long n, m;
cin >> n >> m;
if (n == 1 && m == 1) {
cout << 0 << '\n';
continue;
}
if (n == 1 || m == 1) {
cout << 1 << '\n';
continue;
}
cout << 2 << '\n';
}
}
B. Kalindrome Array
Problem - B - Codeforces
codeforces.com
문제
n개의 정수 (1~n) 수를 담은 배열이 주어질 때, 숫자 하나를 지정하여 배열에 있다면 원하는 만큼 뺄 수 있다. 이때 팰린드롬을 만들 수 있으면 YES를 출력하는 문제
풀이
팰린드롬이 아닌지점부터 시작하여, 무조건 두개의 수중에 하나를 지워야하니까 두개 다 차례대로 지운 후 한번이라도 팰린드롬이 되면 YES를 출력
코드
#include <bits/stdc++.h>
using namespace std;
int a[200001];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++)cin >> a[i];
int l = 1, r = n;
bool flag = true;
while (l <= r) {
if (a[l] != a[r]) {
flag = false;
break;
}
l++; r--;
}
if (flag) {
cout << "YES\n";
continue;
}
flag = true;
int l2 = l, r2 = r;
int num1 = a[l], num2 = a[r];
while (l <= r) {
if (a[l] != a[r]) {
if (a[l] == num1) {
l++;
continue;
}
if (a[r] == num1) {
r--;
continue;
}
flag = false;
break;
}
else {
l++; r--;
}
}
if (flag) {
cout << "YES\n";
continue;
}
flag = true;
l = l2; r = r2;
while (l <= r) {
if (a[l] != a[r]) {
if (a[l] == num2) {
l++;
continue;
}
if (a[r] == num2) {
r--;
continue;
}
flag = false;
break;
}
else {
l++;
r--;
}
}
if (flag) {
cout << "YES\n";
continue;
}
cout << "NO\n";
}
}
자세한 설명에 중점을 두기보다는 대회 기록에 중점을 둔 글입니다 !
틀린 부분은 감사히 지적받겠습니다.
'Algorithm > 코드포스' 카테고리의 다른 글
Codeforces Round #757 (Div. 2) 1548 -> 1495 (0) | 2021.11.28 |
---|---|
Codeforces Round #756 (Div. 3) 1469 -> 1548 (0) | 2021.11.28 |
Educational Codeforces Round 117 (Rated for Div. 2) 1573 -> 1536 (0) | 2021.11.23 |
Codeforces Round #754 (Div. 2) 1567 -> 1572 (0) | 2021.11.13 |
Codeforces Round #753 (Div. 3) , 1457 -> 1567 (0) | 2021.11.03 |