Hello,I want to do this question which is tagged bitmasking.I am not getting how to solve this.Can anybody give me an approach how do I solve this ?
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Hello,I want to do this question which is tagged bitmasking.I am not getting how to solve this.Can anybody give me an approach how do I solve this ?
Название |
---|
Hello, you can observe that 1 <= n <= 1e9. This means that the number "n" has atmost 9 digits. Now let us assume that you need to generate all lucky numbers which have k digits. Now you can see that these k digits must comprise of either 4 or 7. So what you can do is just iterate each number from 0 to (2**k-1) and for each number check if current bit is 0/1. If the current bit is 0 it means 4 else it is 7. As an example let us take k = 2. So you have following cases :
00
01
10
11
Now mapping 0 with 4, 1 with 7, you can see that :
00 : 44
01 : 47
10 : 74
11 : 77
This means that you have generated all lucky numbers with digits : 2. Like this you can iterate k from 1 to 9, and generate the numbers. You can see my solution, it's easy to understand : http://codeforces.me/contest/535/submission/10713472