当前位置:网站首页>Chrysanthemum chain (winter vacation daily question 39)

Chrysanthemum chain (winter vacation daily question 39)

2022-06-25 01:50:00 51CTO

Every day , As part of her walk around the farm , cow Bessie Will pass her favorite grass , One of them is  Chrysanthemum chain ( Winter vacation every day 39)_hash A flower ( Colorful daisies ), The number is  Chrysanthemum chain ( Winter vacation every day 39)_hash_02, Line up .

flowers  Chrysanthemum chain ( Winter vacation every day 39)_#include_03 Yes  Chrysanthemum chain ( Winter vacation every day 39)_hash_04 A flower petal .

As a budding photographer ,Bessie Decided to take some pictures of these flowers .

To be specific , For each pair, meet  Chrysanthemum chain ( Winter vacation every day 39)_i++_05 The flowers of  Chrysanthemum chain ( Winter vacation every day 39)_hash_06,Bessie Will give you flowers  Chrysanthemum chain ( Winter vacation every day 39)_#include_03 To flower  Chrysanthemum chain ( Winter vacation every day 39)_hash_08 All the flowers between ( Include  Chrysanthemum chain ( Winter vacation every day 39)_#include_03 and  Chrysanthemum chain ( Winter vacation every day 39)_hash_08) Take a picture .

later Bessie When you look at these photos, you notice that there are... In some photos 「 Average 」 The flowers of —— One happens to have  Chrysanthemum chain ( Winter vacation every day 39)_i++_11 A petaled flower , among  Chrysanthemum chain ( Winter vacation every day 39)_i++_11 Equal to the average number of petals of all flowers in the picture .

Bessie There are several photos with average flowers ?

Input format
The first line of input contains  Chrysanthemum chain ( Winter vacation every day 39)_hash.

The second line contains  Chrysanthemum chain ( Winter vacation every day 39)_hash Space separated integers  Chrysanthemum chain ( Winter vacation every day 39)_hash_15.

Output format
Output the number of photos with average flowers .

Data range
 Chrysanthemum chain ( Winter vacation every day 39)_#include_16

sample input :

4
1 1 2 3

sample output :

6

Sample explanation
Each photo containing only one flower will be included in the answer ( In this example, there are  Chrysanthemum chain ( Winter vacation every day 39)_i++_17 Zhang ).

in addition , In this example  Chrysanthemum chain ( Winter vacation every day 39)_hash_06 by  Chrysanthemum chain ( Winter vacation every day 39)_ enumeration _19 and  Chrysanthemum chain ( Winter vacation every day 39)_#include_20 The corresponding photos also have average flowers .


      
      
#include<iostream>
#include<unordered_set>

using namespace std;

typedef long long LL;

const int N = 110;

int n;
int q[ N], s[ N];

// Seeking for i There are several sections that meet the requirements of the topic
LL solve( int u){

LL res = 0;
unordered_set < int > hash;

for( int i = u; i <= n; i ++){
hash. insert( q[ i]);
if(( s[ i] - s[ u - 1]) % ( i - u + 1)) continue;
int avg = ( s[ i] - s[ u - 1]) / ( i - u + 1);
if( hash. count( avg)) res ++;
}

return res;
}

int main(){

scanf( "%d", & n);

for( int i = 1; i <= n; i ++){

scanf( "%d", & q[ i]);
s[ i] = s[ i - 1] + q[ i];
}

LL res = 0;
for( int i = 1; i <= n; i ++) res += solve( i);

printf( "%d\n", res);

return 0;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.


原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242133161865.html