日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Moving stones(暴力+思维)

發布時間:2023/12/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Moving stones(暴力+思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

鏈接:https://ac.nowcoder.com/acm/contest/5891/D
來源:牛客網

題目描述
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
一開始這個題目沒有任何的思路。不知道從哪一方面下手。。
對于這個序列中最小的那個數字,我們肯定是要勻給它一些石子的。經過這樣若干次操作之后,在符合的條件下,就會達到平均。那么我們就模擬這個過程。這個題目數據量不是很大,就能過了。更好的方法暫時沒有想到,希望路過的大佬可以指正。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=1e3+100; int a[maxx]; vector<int> v; int n;int main() {int t;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&a[i]);sort(a+1,a+1+n);int sum=0;for(int i=1;i<=n;i++) sum+=a[i];if(sum%n) cout<<"No"<<endl;else{v.clear();for(int i=1;i<=n;i++) v.push_back(a[i]);int flag=0;int cnt=0;while(cnt<=1500){sort(v.begin(),v.end());if(v[0]==v.back()) {flag=1;break;}if(v[1]==0) break;//出現0了,說明就要變成負數了,這樣肯定不行。v[0]+=(n-1);for(int i=1;i<n;i++) v[i]--;cnt++;}if(flag==0) cout<<"No"<<endl;else cout<<"Yes"<<endl;}}return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的Moving stones(暴力+思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。