In Java, why is it that the code a^=b^=a^=b does not swap the values of a and b, while in C++, such code works? For example if a=1, and b=5, in Java, after doing a^=b^=a^=b, a=0, b=1.
# | User | Rating |
---|---|---|
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 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
In Java, why is it that the code a^=b^=a^=b does not swap the values of a and b, while in C++, such code works? For example if a=1, and b=5, in Java, after doing a^=b^=a^=b, a=0, b=1.
I was trying to figure out why there is a difference in verdict in these two solutions for 1354F - Summoning Minions (summoning minions):
Solution that gives WA on test case 32 of test 2: https://pastebin.com/EzbSDw3Z
AC Solution: https://pastebin.com/DjFkheFs
The only difference between these two solutions is that when deciding whether to include one of the minions, in WA solution, I try to find max(dp[i-1][j]+minion[i].b*(k-1), dp[i-1][j-1]+minion[i].a+minion[i].b*(j-1)), which should give the actual value of the dp at that state.
On the other hand, the AC solution finds max(dp[i-1][j], dp[i-1][j-1]+minion[i].a-minion[i].b*(k-j)). I expected both methods to produce the same result, and tried to find an instance where the methods would produce different results, but I could not.
Can anyone explain why the first method causes WA?
Name |
---|