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 | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 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 ?
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://codeforces.net/contest/535/submission/10713472