CF1118B.Tanya and Candies
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Tanya has n candies numbered from 1 to n. The i-th candy has the weight ai.
She plans to eat exactly n−1 candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day.
Your task is to find the number of such candies i (let's call these candies good) that if dad gets the i-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days. Note that at first, she will give the candy, after it she will eat the remaining candies one by one.
For example, n=4 and weights are [1,4,3,3]. Consider all possible cases to give a candy to dad:
- Tanya gives the 1-st candy to dad (a1=1), the remaining candies are [4,3,3]. She will eat a2=4 in the first day, a3=3 in the second day, a4=3 in the third day. So in odd days she will eat 4+3=7 and in even days she will eat 3. Since 7=3 this case shouldn't be counted to the answer (this candy isn't good).
- Tanya gives the 2-nd candy to dad (a2=4), the remaining candies are [1,3,3]. She will eat a1=1 in the first day, a3=3 in the second day, a4=3 in the third day. So in odd days she will eat 1+3=4 and in even days she will eat 3. Since 4=3 this case shouldn't be counted to the answer (this candy isn't good).
- Tanya gives the 3-rd candy to dad (a3=3), the remaining candies are [1,4,3]. She will eat a1=1 in the first day, a2=4 in the second day, a4=3 in the third day. So in odd days she will eat 1+3=4 and in even days she will eat 4. Since 4=4 this case should be counted to the answer (this candy is good).
- Tanya gives the 4-th candy to dad (a4=3), the remaining candies are [1,4,3]. She will eat a1=1 in the first day, a2=4 in the second day, a3=3 in the third day. So in odd days she will eat 1+3=4 and in even days she will eat 4. Since 4=4 this case should be counted to the answer (this candy is good).
In total there 2 cases which should counted (these candies are good), so the answer is 2.
塔尼娅有 n 颗编号从 1 到 n 的糖果。第 i 颗糖果的重量为 ai。
她计划恰好吃掉 n−1 颗糖果,并将剩下的一颗糖果送给爸爸。塔尼娅按编号递增的顺序吃糖果,每天恰好吃一颗。
你的任务是:找出满足如下条件的糖果编号 i(我们称这些糖果为“好糖果”)的个数:若爸爸得到的是第 i 颗糖果,则塔尼娅在偶数天(第 2,4,6,… 天)所吃糖果的重量之和,等于她在奇数天(第 1,3,5,… 天)所吃糖果的重量之和。注意:她首先将一颗糖果送给爸爸,之后再按编号顺序逐颗吃掉剩下的糖果。
例如,n=4,糖果重量为 [1,4,3,3]。我们考虑所有可能送给爸爸的糖果:
- 塔尼娅把第 1 颗糖果送给爸爸(a1=1),剩余糖果为 [4,3,3]。她将在第 1 天吃 a2=4,第 2 天吃 a3=3,第 3 天吃 a4=3。因此,她在奇数天吃的糖果总重为 4+3=7,在偶数天吃的糖果总重为 3。由于 7=3,该情况不计入答案(这颗糖果不是“好糖果”)。
- 塔尼娅把第 2 颗糖果送给爸爸(a2=4),剩余糖果为 [1,3,3]。她将在第 1 天吃 a1=1,第 2 天吃 a3=3,第 3 天吃 a4=3。因此,她在奇数天吃的糖果总重为 1+3=4,在偶数天吃的糖果总重为 3。由于 4=3,该情况不计入答案(这颗糖果不是“好糖果”)。
- 塔尼娅把第 3 颗糖果送给爸爸(a3=3),剩余糖果为 [1,4,3]。她将在第 1 天吃 a1=1,第 2 天吃 a2=4,第 3 天吃 a4=3。因此,她在奇数天吃的糖果总重为 1+3=4,在偶数天吃的糖果总重为 4。由于 4=4,该情况应计入答案(这颗糖果是“好糖果”)。
- 塔尼娅把第 4 颗糖果送给爸爸(a4=3),剩余糖果为 [1,4,3]。她将在第 1 天吃 a1=1,第 2 天吃 a2=4,第 3 天吃 a3=3。因此,她在奇数天吃的糖果总重为 1+3=4,在偶数天吃的糖果总重为 4。由于 4=4,该情况应计入答案(这颗糖果是“好糖果”)。
总计有 2 种情况应被计入(即有 2 颗“好糖果”),因此答案为 2。
输入格式
The first line of the input contains one integer n (1≤n≤2⋅105) — the number of candies.
The second line of the input contains n integers a1,a2,…,an (1≤ai≤104), where ai is the weight of the i-th candy.
输入的第一行包含一个整数 n(1≤n≤2⋅105)—— 表示糖果的数量。
输入的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤104),其中 ai 表示第 i 颗糖果的重量。
输出格式
Print one integer — the number of such candies i (good candies) that if dad gets the i-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days.
输出一个整数——满足条件的糖果 i(好糖果)的个数:即如果爸爸拿走第 i 颗糖果,则塔尼娅在偶数天吃的糖果重量之和等于她在奇数天吃的糖果重量之和。
输入输出样例
输入#1
7 5 5 4 5 5 5 6
输出#1
2
输入#2
8 4 8 8 7 8 4 4 5
输出#2
2
输入#3
9 2 3 4 2 2 3 2 2 4
输出#3
3
说明/提示
In the first example indices of good candies are [1,2].
In the second example indices of good candies are [2,3].
In the third example indices of good candies are [4,5,9].
在第一个例子中,优质糖果的索引为 [1,2]。
在第二个例子中,优质糖果的索引为 [2,3]。
在第三个例子中,优质糖果的索引为 [4,5,9]。
输入解题思路,AI测评打分。不知道怎么写?