Code forces 103A---Testing Pants for Sadness

点击打开链接

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;
}
时间: 2024-11-08 19:58:13

Code forces 103A---Testing Pants for Sadness的相关文章

贪心-Code forces -387B -George and Round

Code forces -387B -George and Round   description George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by intege

Code forces 200C---Football Championship

点击打开链接 题目: C. Football Championship time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Any resemblance to any real championship and sport is accidental. The Berland National team takes part i

REGULAR EXPRESSION IN VBSCRIPT

express|vbscript|express|vbscript   REGULAR EXPRESSION IN VBSCRIPTObject RegExp is used to create and execute regular expression Ex.Code:strTarget="test testing tested attest late start"Set objRegExp= New RegExp   'create a regular expression ob

【转载】stackoverflow 上关于 rebar 的讨论

[ rebar-include-ext-libs-error ]  Your config file worked for me so I'd suggest doing the following:  make sure you have git installed put the most recent build of rebar in your project directory use a Makefile like the one I described here delete yo

ISO 4217 货币(货币符号)及基金编码

货币符号 货币符号是一种常被用来作为货币名称的图像速记符号.发行货币是一个国家主权的一部分,一般每个主权国家都有自己的货币.世界货币符号可以按照五大洲来分,在此收集整理了世界200多个国家的货币名称及货币符号,例如,人民币的表示符号是"¥".但为了区别货币符号同样是"¥"的日圆,人民币的符号可写为"RMB¥".以下是五大洲世界各主要国家和地区的货币符号大全,可供参考.     [亚洲]   亚洲 货币名称 货币符号 中文 英文 原有旧符号 标准符

Zend Framework教程之响应对象的封装Zend_Controller_Response实例详解_php实例

本文实例讲述了Zend Framework教程之响应对象的封装Zend_Controller_Response用法.分享给大家供大家参考,具体如下: 概述 响应对象逻辑上是请求对象的搭档.目的在于收集消息体和/或消息头,因而可能返回大批的结果. Zend_Controller_Response响应对象的基本实现 ├── Response │   ├── Abstract.php │   ├── Cli.php │   ├── Exception.php │   ├── Http.php │  

Common ASP.NET Code Techniques (DPC&amp;amp;DWC Reference)--6

asp.net Figure 2.5Output of Listing 2.1.5 when viewed through a browser. If you've worked with classic ASP, you are likely familiar with the concept of session-level variables. These variables are defined on a per-user basis and last for the duration

Code Complete-13/7/23

What is "construction"?    Hava u ever  used construction paper to make some things?What is " software construction"? problem definition requirements development construction planning software architecture or higt-level design detailed

笔记:Automated Journey Testing with Cascade

感觉是一个很好的介绍Cascade的文章. Key Takeaways The problem of testing a system is becoming harder as we have larger teams, as we have more processes and as we adopt microservices architecture.(是的,微服务要背锅) The testing problem is fundamentally different moving for