Algorithm/📊 Problem Solving

[백준/BOj] 11675 - Jumbled Communication

posted by sangmin

11675 - Jumbled Communication

📌 문제

Your best friend Adam has recently bought a Raspberry Pi and some equipment, including a wireless temperature sensor and a 433MHz receiver to receive the signals the sensors sends. Adam plans to use the Raspberry Pi as an in-door display for his weather sensor. As he is very good with electronics, he quickly managed to get the receiver to receive the signals of the sensor. However, when he looked at the bytes sent by the sensor he could not make heads or tails of them. After some hours looking through a lot of websites, he found a document explaining that his weather sensor scrambles the data it sends, to prevent it from being used together with products from other manufacturers.

Luckily, the document also describes how the sensor scrambles its communication. The document states that the sensor applies the expression x ^ (x << 1) to every byte sent. The ^ operator is bit-wise XOR1, e.g., 10110000 ^ 01100100 = 11010100. The << operator is a (non-circular) left shift of a byte value2, e.g., 10111001 << 1 = 01110010.

In order for Adam’s Raspberry Pi to correctly interpret the bytes sent by the weather sensor, the transmission needs to be unscrambled. However, Adam is not good at programming (actually he is a pretty bad programmer). So he asked you to help him and as a good friend, you are always happy to oblige. Can you help Adam by implementing the unscrambling algorithm?

1In bit-wise XOR, the ith bit of the result is 1 if and only if exactly one of the two arguments has the ith bit set.

2In x << j, the bits of x are moved j steps to the left. The j most significant bits of x are discarded, and j zeroes are added as the least significant bits of the result.

📋 코드

N = int(input())
arr = list(map(int, input().split()))

for a in arr:
    for i in range(100001):
        if int(bin(i ^ (i << 1) & 255), 2) == a:
            print(i, end=' ')
            break

💡 한마디

처음에 문제를 잘못 해석해서 한참동안 반대로 풀고 있었다. 😂

 

11675번: Jumbled Communication

Your best friend Adam has recently bought a Raspberry Pi and some equipment, including a wireless temperature sensor and a 433MHz receiver to receive the signals the sensors sends. Adam plans to use the Raspberry Pi as an in-door display for his weather se

www.acmicpc.net

 

'Algorithm > 📊 Problem Solving' 카테고리의 다른 글

[백준/BOJ] 1043 - 거짓말  (0) 2021.03.06
[백준/BOJ] 14569 - 시간표 짜기  (0) 2021.03.05
[백준/BOJ] 12813 - 이진수 연산  (0) 2021.03.03
[백준/BOJ] 11657 - 타임머신  (0) 2021.03.01
[백준/BOJ] 1058 - 친구  (0) 2021.02.27