HBC51450SQL测试Removing Stones题解

痛心疾首 算法基础篇 27 0
题库丰富多样,涵盖各个领域,全网最全C++题库,让您在练习中不断成长!
Summer vacation is coming and Mark has returned home from his university having successfully survived the exam week. Today, he is very bored. So his friend Alice challenges him to play a game with s

Summer vacation is coming and Mark has returned home from his university having successfully survived the exam week. Today, he is very bored. So his friend Alice challenges him to play a game with stones which is invented by her. Alice gives Mark N N N piles of stones numbered from 1 1 1 to N N N, and there are aia_iai​ stones in the i i i-th pile. The rules of the game are simple: Mark will try to remove all stones. In each move, Mark chooses two different non-empty piles and removes one stone from each of those two piles. Mark can perform any number of moves. If all the piles are empty after some number of moves, Mark wins the game. If he can't make a valid move but not all piles are empty, he loses the game. Obviously, if the total number of stones is odd, then Mark is not able to win the game. So there is an additional rule: if initially, the total number of stones is odd, then Mark removes a single stone from the pile with the fewest stones before starting the game. If there are multiple piles with the smallest number of stones, Mark chooses one among them to remove a stone. Mark found the optimal strategy for Alice's game very quickly and gets bored again. Also, he noticed that for some configuration of stones there is no way to win. So he challenges you to solve this problem: count the number of integer pairs (l,r) (1≤l

HBC51450SQL测试Removing Stones题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断挑战自我,才能突破极限!全网最全C++题库,让您在编程道路上越走越远。

标签: HBC51450SQL测试Removing Stones题解