๋นํธ ์ฐ์ฐ์
์ ์ ํ์ ์ ํผ์ฐ์ฐ์์๋ง ์ ์ฉ๋ ์ ์๋ค.
๊ธฐ๋ณธ ์๋ฆฌ
- A^B๋ ๊ฐ์ด ๊ฐ์ผ๋ฉด 0 ๋ค๋ฅด๋ฉด 1์ ๋ฐํํ๋ค.
- ~A๋ -A-1๊ณผ ๊ฐ๋ค.
- ์ํํธ ์ฐ์ฐ์์์ ๋น ๋นํธ์ ๋ชจ๋ 0์ด ์ฑ์์ง์ง๋ง >> ์ฐ์ฐ์์์ A๊ฐ ์์์ธ ๊ฒฝ์ฐ์ 1์ด ์ฑ์์ง๋ค.
๋ฌธ์
https://tech.kakao.com/2017/09/27/kakao-blind-recruitment-round-1/
์นด์นด์ค ์ ์ ๊ณต์ฑ 1์ฐจ ์ฝ๋ฉ ํ ์คํธ ๋ฌธ์ ํด์ค
‘๋ธ๋ผ์ธ๋’ ์ ํ์ผ๋ก ์ค์๋์ด ์์๋ถํฐ ์์ฒญ๋ ํ์ ๋ฅผ ๋ชฐ๊ณ ์จ ์นด์นด์ค ๊ฐ๋ฐ ์ ์ ๊ณต์ฑ. ๊ทธ ์ฒซ ๋ฒ์งธ ๊ด๋ฌธ์ธ 1์ฐจ ์ฝ๋ฉ ํ ์คํธ๊ฐ ์ง๋ 9์ 16์ผ(ํ ) ์คํ 2์๋ถํฐ 7์๊น์ง ์ฅ์ฅ 5์๊ฐ ๋์ ์จ๋ผ์ธ๏ฟฝ๏ฟฝ
tech.kakao.com
#include <iostream>
using namespace std;
int main()
{
int n = 0;
cout << "์ง๋ ํ ๋ณ์ ํฌ๊ธฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์: ";
cin >> n;
int* arr1 = new int[n];
int* arr2 = new int[n];
cout << "์ง๋ 1์ ์ ์ ๋ฐฐ์ด์ ์
๋ ฅํด์ฃผ์ธ์: ";
for (int i = 0; i < n; ++i)
cin >> arr1[i];
cout << "์ง๋ 2์ ์ ์ ๋ฐฐ์ด์ ์
๋ ฅํด์ฃผ์ธ์: ";
for (int i = 0; i < n; ++i)
cin >> arr2[i];
int* map = new int[n];
for (int i = 0; i < n; ++i)
map[i] = arr1[i] | arr2[i]; // ์ง๋ 1, 2๋ก ์ ์ฒด ์ง๋ ๋ง๋ค๊ธฐ
int d = 1 << (n - 1); // n์ด 4์ผ๋, 1000 -> ๊ฐ์ฅ ์ฒซ ๋ฒ์งธ ๋นํธ์ and ์ฐ์ฐ์ ํ๊ธฐ ์ํด
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (map[i] & d)
cout << "#";
else
cout << " ";
map[i] <<= 1; // ๋นํธ ์ผ์ชฝ์ผ๋ก 1 ์ด๋ ํ ํ ๋น
}
cout << endl;
}
return 0;
}
https://www.acmicpc.net/problem/11811
11811๋ฒ: ๋ฐ์ค์คํ
๋ฌธ์ ์ ์ ์ ๋ค์ด ์ด๋ฐ์ ์๋ฌด๋ ๋ฐ์ค์คํ์ ์นจํฌํ์ฌ ํ๊ดดํ๋ ์ผ์ด๋ค. ๋ฐ์ค์คํ๋ฅผ ํ๊ดดํ๊ธฐ ์ํด์๋ ๊ธธ์ด N์ ์์ด ์๋ ์ ์ ์์ด ai๊ฐ ํ์ํ๋ค. ๊ทธ๋ฌ๋ ์ด๋ฐ์ ์ด ์์ด์ ๊ฐ์ง๊ณ ์์ง ์๋ค. ๋์ ๊ทธ์๊ฒ๋ ์ค๋ ์น๊ตฌ ๋ค์ค ๋ฒ ์ด๋์๊ฒ ๋ฐ์ ์ชฝ์ง๊ฐ ํ๋ ์๋ค. ์ด ์ชฝ์ง์๋ ๊ทธ ์์ด์ด ๋ง์กฑํด์ผ ํ๋ ์กฐ๊ฑด์ด ์ ํ ์๋ค. ์ด ์ชฝ์ง์๋ ํฌ๊ธฐ N์ ์ ์ฌ๊ฐ ํ๋ ฌ์ด ์๋๋ฐ, i๋ฒ์งธ ํ j๋ฒ์งธ ์ด์ ์ ํ ์ซ์๋ ai์ aj์ ๋นํธ์ฐ์ฐ and๋ฅผ ์ํํ ๊ฒฐ๊ณผ๊ฐ์ด๋ค. ํ์ง๋ง
www.acmicpc.net
#include <iostream>
using namespace std;
int main(void)
{
int N;
cin >> N;
for (int i = 0; i < N; ++i) {
int a = 0, tmp;
for (int j = 0; j < N; ++j) {
cin >> tmp;
if (i != j)
a = a | tmp;
}
cout << a << " ";
}
return 0;
}
https://leetcode.com/problems/single-number-ii/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
#include <vector>
using namespace std;
class Solution {
public:
int singleNumber(vector<int>& nums) {
int first = 0, second = 0;
for (int i = 0; i < nums.size(); ++i) {
first = (first ^ nums[i]) & (~second);
second = (second ^ nums[i]) & (~first);
}
return first;
}
};
https://leetcode.com/problems/bitwise-and-of-numbers-range/description/
class Solution {
public:
int rangeBitwiseAnd(int left, int right) {
while (left < right)
right = right & (right - 1);
return right;
}
};