luogu P1031 sharing Solitaire greedy

 1 #include <cstdio>
 2 using namespace std;
 3 int n,a[110],tot,res;
 4 int check(int x)
 5 {
 6     if (x != 0)
 7         return 1;
 8     return 0;
 9 }
10 int main()
11 {
12     scanf("%d",&n);
13     for (int i = 1;i <= n;i++)
14     {
15         scanf("%d",&a[i]);
16         tot += a[i];
17     }
18     for (int i = 1;i <= n;i++)
19     {
20         a[i + 1] -= tot / n - a[i];
21         res += check(tot / n - a[i]);
22     }
23     printf("%d\n",res);
24 }

 

Guess you like

Origin www.cnblogs.com/iat14/p/11232359.html