Moving stones(暴力+思维)
鏈接:https://ac.nowcoder.com/acm/contest/5891/D
來源:??途W
題目描述
One day, GK was getting very bored with palying stones. So he made a rule for himself:
There are n piles of stones in total, at least 0 stones in each pile. You can select a pile of stones each time you move, and then take out one stone from each other (n-1 in total) and put them into the selected pile. The number of stones in any pile at any time cannot be less than 0.That is to say, before you select a pile of stones to add to it, if there have a pile of 0 stones in other piles, you will not be able to select this pile of stones.(For example,there are 3 piles of stones,1 4 1,If you choose the second pile, it will become 0 6 0,and you won’t be able to do anything next )
GK wants to know if he can make every pile of stones equal by lots of operation as many times as he want. GK never does anything uncertain, so after a long meditation, he decides to ask for your help.
輸入描述:
The first line is an integer T (1 ≤ T ≤ 1000), indicates that there are T-group data.
Each group of test data has two lines, the first line has an integer n (1≤n≤100), which means there are n piles of stones, the second line has n integers a1, a2…an (0 ≤ai ≤1000), which means the number of stones in each pile.
輸出描述:
Each group of test data corresponds to an output. If GK can meet the requirements after any number of operations,print"Yes". Otherwise, print “No”.
There is no extra space at the beginning and end of the line, and each group of output takes up one line.
示例1
輸入
復制
2
3
1 2 3
3
2 2 2
輸出
復制
No
Yes
一開始這個題目沒有任何的思路。不知道從哪一方面下手。。
對于這個序列中最小的那個數字,我們肯定是要勻給它一些石子的。經過這樣若干次操作之后,在符合的條件下,就會達到平均。那么我們就模擬這個過程。這個題目數據量不是很大,就能過了。更好的方法暫時沒有想到,希望路過的大佬可以指正。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Moving stones(暴力+思维)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 产品经理解答理想L7最热门的10个问题:
- 下一篇: 世嘉联手横尾太郎推出新作《404 GAM