点击打开链接

A. Testing Pants for Sadness
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".

The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.

A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.

Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?

Input

The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.

Output

Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Sample test(s)
input
2
1 1

output
2

input
2
2 2

output
5

input
1
10

output
10

Note

Note to the second sample. In the worst-case scenario you will need five clicks:

  • the first click selects the first variant to the first question, this answer turns out to be wrong.
  • the second click selects the second variant to the first question, it proves correct and we move on to the second question;
  • the third click selects the first variant to the second question, it is wrong and we go back to question 1;
  • the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
  • the fifth click selects the second variant to the second question, it proves correct, the test is finished

题目意思:    有一个人在做题目,现在有n道题,每道题会有Ai个选择,现在题目说这个人记忆很好可以记住自己前面选择的,但是只要这个选错,那么所有的问题都要从新选择,问这个人最多要选择几次

解题思路:    我们知道如果要让选择的次数最多,那么就是这个人最后一次才选上答案,那么我们只要知道这个原来,就可以推出一个规律,然后我们去for一遍即可(注意用__int64)

代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;int n;
__int64 sum;
__int64 ans[110];//
void solve(){sum = 0;int tmp;for(int i = 1; i <= n ; i++){ tmp = 0;for(int j = 1 ; j < i ; j++) tmp++;sum += tmp*(ans[i]-1) + ans[i];//推出的公式}printf("%I64d\n" , sum);
}//主函数
int main(){//freopen("input.txt" , "r" , stdin);while(scanf("%d" , &n) != EOF){memset(ans , 0 , sizeof(ans));for(int i = 1 ; i <= n ; i++)      cin>>ans[i];solve();}return 0;
}

更多详细信息请查看 java教程网 http://www.itchm.com/forum-59-1.html

Code forces 103A---Testing Pants for Sadness相关推荐

  1. CF 103A.Testing Pants for Sadness

    题目:http://icpc.njust.edu.cn/Problem/CF/103A/ AC代码(C++): #include <iostream> #include <queue ...

  2. CodeForces 103A Testing Pants for Sadness

    http://codeforces.com/problemset/problem/103/A 看懂题意就可以了 简单 #include<bits/stdc++.h> using names ...

  3. Codeforces 103A Testing Pants for Sadness

    题意: 给你n道题,每题有a[i]个选项,选错一个要退回到第一题重新开始,问你最少需要试几次才能在最坏的情况下做对全部的题目. 思路: 最坏情况下也就是说对于每个a[i]你都要试a[i]次,而且其中a ...

  4. 【codeforces103A】Testing Pants for Sadness

    CodeForces103A :Testing Pants for Sadness 时间限制:2000MS    内存限制:262144KByte   64位IO格式:%I64d & %I64 ...

  5. codeforces-103A Testing Pants for Sadness(简单递推)

    链接:http://codeforces.com/problemset/problem/103/A 题意:有n个问题,每个问题有ai种回答,每次只有回答正确才能回答下一个问题.回答 错误的话要重新回到 ...

  6. 题解 CF103A 【Testing Pants for Sadness】

    解题思路 首先要知道每次尝试需要重新再做一遍(要是我就没有这个耐力),重新做就是把已经做过的题数+1重复选项数-1遍,加上最后的选项数(不理解可以手动模拟一下,还是用实打实的手写吧,我拿电脑不便于记录 ...

  7. CodeForces 104B-Testing Pants for Sadness(思维题)

    The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he shou ...

  8. Code Forces Bear and Forgotten Tree 3 639B

    B. Bear and Forgotten Tree 3 time limit per test2 seconds memory limit per test256 megabytes inputst ...

  9. 【Code forces】63B Settlers' Training

    http://codeforces.com/problemset/problem/63/B 给你一串数字,直到所有数字都变为k为止,相同的数为一组,在一次中,所有不同的数都加1 1 2 2 3  →  ...

最新文章

  1. 解决Android图库不识别.nomedia的问题
  2. 十三、“词短情长书不尽,桃花潭水是我心。”(2021.2.12)
  3. Linux 基础学习大考核
  4. Ubuntu12下安装redis(多图版)+ Jedis连接Redis
  5. 【OpenPose-Windows】error1 OpenPose项目加载失败
  6. Linux内核crypto子系统的调用逻辑
  7. SpringBoot —— Bean的注入方式
  8. python文件writelines_python 写文件write(string), writelines(list)
  9. java 实现压缩zip的几种方案
  10. EntityFramework走马观花之CRUD(上)
  11. 在PHP代码中处理JSON 格式的字符串的两种方法:
  12. 无线SD-WAN提供商Cradlepoint完成C轮融资8900万美元
  13. 树、森林和二叉树之间的转换
  14. python3内存分析_调试和分析 - tracemalloc —- 跟踪内存分配 - 《Python 3.7 标准库》 - 书栈网 · BookStack...
  15. 离散数学计算机科学与技术答案,2计算机科学与技术专业本科离散数学期末复习题2...
  16. Wireshark通过TCP协议抓取QQ好友IP以及定位
  17. 连接服务器框架协议通信,通信服务协议范本3篇.doc
  18. 服务器快速搭建AList集成网盘网站【宝塔面板一键部署AList/Docker】
  19. Spring: error at ::0 can‘t find referenced pointcut的错误并解决
  20. icpc 昆明 A.AC

热门文章

  1. AssetClub游戏攻略
  2. 解决element-UI改变分页时,表格序号总是从1开始的问题.
  3. 使用frida发送微信消息给好友
  4. 各大网站架构总结笔记
  5. 聊聊真实的 Android TV 开发技术栈
  6. 图像处理 亮度、CLAHE处理、MSRCR
  7. 3-「季淳卿」 运算符+原码、反码、补码
  8. 如何预约华为认证笔试考试之Pearson VUE网站预约
  9. 常用的数据分析图表及方法介绍 1
  10. 2021_lg_04.sql_2021窗口函数的使用与偏移函数在日期资金上的使用案例代码