当前位置:网站首页>菊花链(寒假每日一题 39)
菊花链(寒假每日一题 39)
2022-06-24 21:38:00 【51CTO】
每天,作为她绕农场行走的一部分,奶牛 Bessie 会经过她最喜爱的草地,其中种有 朵花(五颜六色的雏菊),编号为
,排列成一行。
花 有
朵花瓣。
作为一名崭露头角的摄影家,Bessie 决定给这些花拍些照片。
具体地说,对于每一对满足 的花
,Bessie 会给从花
到花
之间的所有花(包括
和
)拍一张照。
后来 Bessie 查看这些照片时注意到有些照片里存在「平均」的花——一朵恰好有 朵花瓣的花,其中
等于照片中所有花的花瓣数量的平均值。
Bessie 的照片中有几张存在平均的花?
输入格式
输入的第一行包含 。
第二行包含 个空格分隔的整数
。
输出格式
输出存在平均的花的照片数量。
数据范围
输入样例:
4
1 1 2 3
输出样例:
6
样例解释
每张仅包含一朵花的照片均会被计入答案(在这个样例中有 张)。
另外,在这个样例中 为
和
所对应的照片也存在平均的花。
using
namespace
std;
typedef
long
long
LL;
const
int
N
=
110;
int
n;
int
q[
N],
s[
N];
// 求以 i 为起点的区间有几个满足题目要求的
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.
边栏推荐
- 为猪脸识别而进行自己数据集的构建、训练「建议收藏」
- Program.launch(xxx)打开文件
- 广发期货安全吗?开户需要什么东西?
- "One good programmer is worth five ordinary programmers!"
- Introduction to bi-sql wildcards
- Tencent has completed the comprehensive cloud launch to build the largest cloud native practice in China
- Using macro code to generate handwriting automatically in word or WPS
- Merge sort template & understanding
- Abnova丨CSV 磁珠中英文说明
- IPC mechanism
猜你喜欢

动手学数据分析 数据建模和模型评估

Bi-sql index

PS5连接OPPO K9电视不支持2160P/4K

论文翻译 | RandLA-Net: Efficient Semantic Segmentation of Large-Scale Point Clouds

Application session coverage solutions with different ports on the same server
The latest QQ wechat domain name anti red PHP program source code + forced jump to open

明日考试 最后一天如何备考?二造考点攻略全整理

2种常见的设备稼动率OEE监测方法

修身励学篇

海河实验室创新联合体成立 GBASE成为首批创新联合体(信创)成员单位
随机推荐
Bi-sql between
Icml2022 | establishing a continuous time model of counterfactual results using neural control differential equations
Reading notes at night -- deep into virtual function
实验5 8254定时/计数器应用实验【微机原理】【实验】
PMP考试“临门一脚”如何踢得漂亮?
Redis persistence
Fan benefits, JVM manual (including PDF)
How much commission does CICC wealth securities open an account? Is stock account opening and trading safe and reliable?
Tencent cloud wecity Hello 2022!
Huawei laptop, which grew against the trend in Q1, is leading PC into the era of "smart office"
matlab 取整
Ps5 connected to oppo K9 TV does not support 2160p/4k
天书夜读笔记——8.4 diskperf反汇编
After the college entrance examination, the following four situations will inevitably occur:
Basic knowledge of assembly language (2) -debug
Status quo analysis: how "one cloud and multi-core" can promote the rapid deployment of information innovation projects
海河实验室创新联合体成立 GBASE成为首批创新联合体(信创)成员单位
Tencent has completed the comprehensive cloud launch to build the largest cloud native practice in China
Tencent moved!
天书夜读笔记——反汇编引擎xde32