BOJ::11723 집합


비트마스크 및 비트 시프트연산에 관련된 문제이다.

잘 모르는 내용이라 공부하면서 풀었다.

그리고 처음에 <iostream> 및 <string> 을 이용하여 풀려고 했는데 시간초과가 나와서

방법을 바꿔 풀어보았다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <cstring>
#include <math.h>
using namespace std;
 
int main() {
    unsigned int mask = 0;
    int m;
    scanf("%d"&m);
 
    for (int i = 0; i < m; i++) {
        char s[10];
        int n;
 
        scanf("%s"&s);
        if (s[1== 'd') {
            scanf("%d"&n);
            mask |= (1 << n);
        }
        else if (s[0== 'r') {
            scanf("%d"&n);
            mask &= ~(1 << n);
        }
        else if (s[0== 'c') {
            scanf("%d"&n);
            if (mask & (1 << n)) {
                printf("1\n");
            }
            else {
                printf("0\n");
            }
        }
        else if (s[0== 't') {
            scanf("%d"&n);
            mask ^= (1 << n);
        }
        else if (s[1== 'l') {
            mask = pow(221)-1;
        }
        else if (s[0== 'e') {
            mask = 0;
        }
    }
}
cs


'BOJ::문제풀이' 카테고리의 다른 글

11728 배열 합치기  (0) 2018.02.07
10942 팰린드롬?  (2) 2018.02.05
2470 두 용액  (0) 2018.01.30
14891 톱니바퀴  (0) 2018.01.28
14503 로봇 청소기  (0) 2018.01.28

+ Recent posts