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.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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?
Название |
---|