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 ?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 151 |
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 ?
Name |
---|
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://mirror.codeforces.com/contest/535/submission/10713472