※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 3533번 문제인 Explicit Formula이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/3533
3533번: Explicit Formula
Consider 10 Boolean variables x1, x2, x3, x4, x5, x6, x7, x8, x9, and x10. Consider all pairs and triplets of distinct variables among these ten. (There are 45 pairs and 120 triplets.) Count the number of pairs and triplets that contain at least one variab
www.acmicpc.net
각 2-tuple과 3-tuple들에 대한 값을 각각 직접 계산하는 것으로 문제를 해결할 수 있다.
물론 문제에 나와있는 것과 같은 무식한 식을 직접 작성할 필요는 없다. 대신 아래와 같이 반복문을 이용해 모든 경우에 접근하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int arr[10];
int ans = 0;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < 10; i++) cin >> arr[i];
for (int i = 0; i < 10; i++) {
for (int j = i + 1; j < 10; j++) {
ans ^= (arr[i] | arr[j]);
for (int k = j + 1; k < 10; k++) {
ans ^= (arr[i] | arr[j] | arr[k]);
}
}
}
cout << ans;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 10902 // C++] Penalty calculation (1) | 2022.12.10 |
---|---|
[BOJ 24349 // C++] МЕД (0) | 2022.12.10 |
[BOJ 12572 // C++] Rope Intranet (Large) (0) | 2022.12.10 |
[BOJ 12571 // C++] Rope Intranet (Small) (0) | 2022.12.10 |
[BOJ 24080 // C++] 複雑な文字列 (Complex String) (0) | 2022.12.10 |