`
yiheng
  • 浏览: 155449 次
社区版块
存档分类

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;
}



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

相关推荐

    code-forces-solutions:Code Force解决问题的方法

    "code-forces-solutions"是一个集合了在Code Forces上解决问题的方法和代码的资源库,旨在帮助参赛者理解和解决各类编程问题。这个压缩包可能包含了作者或社区成员对Code Forces题目所提交的C++解决方案。 在C++...

    PlumePack-Forces-nationales-alpha-1.jar

    PlumePack-Forces-nationales-alpha-1.jar

    Simscape-Multibody-Contact-Forces-Library-21.2.5.1

    Simscape-Multibody-Contact-Forces-Library-21.2.5.1

    VR-Forces 能力说明

    VR-Forces 能力说明 VR-Forces 是 MAK 公司开发的一款功能强大且灵活的计算机生成力量(CGF)平台,旨在为您的合成环境提供都市、战场、海洋和航空活动的模拟场景。该平台可以满足您各种模拟需求,从训练和任务彩排...

    PyPI 官网下载 | forces-20.11.42710-py3-none-any.whl

    标题中的“PyPI 官网下载 | forces-20.11.42710-py3-none-any.whl”表明这是一个从Python Package Index(PyPI)官方源下载的软件包,名为“forces”。PyPI是Python社区广泛使用的第三方库分发平台,允许开发者发布...

    PyPI 官网下载 | forces-20.11.17246.tar.gz

    标题中的“PyPI 官网下载 | forces-20.11.17246.tar.gz”表明这是一个从Python Package Index(PyPI)官方源下载的软件包,名为`forces-20.11.17246.tar.gz`。PyPI是Python开发者发布和分享自己编写的Python软件包的...

    RTSP-Camera-for-Android-视频监控demo

    This network is especially designed to support mobile disaster teams and dismounted military forces. Another AMES sub project that is also publically available on github is the Web Services Security ...

    VR-Forces Users Guide 4.6

    ### VR-Forces 4.6 用户指南关键知识点解析 #### 一、概述 - **产品版本与版权信息**:VR-Forces 4.6 版本是 VT MAK 公司于 2018 年发布的高级仿真软件。该软件受版权保护,未经 VT MAK 书面许可,不得复制或再生产...

    PyPI 官网下载 | forces-20.11.3920.tar.gz

    标题中的"PyPI 官网下载 | forces-20.11.3920.tar.gz"表明这是一个从Python Package Index (PyPI)官方源下载的软件包,名为`forces-20.11.3920.tar.gz`。PyPI是Python社区广泛使用的仓库,用于发布和管理Python第三...

    Python库 | forces-20.8.25626.tar.gz

    标题中的“forces-20.8.25626.tar.gz”是一个Python库的压缩包文件,基于描述我们可以推断这是一个特定版本的Python库,版本号为20.8.25626,其文件格式是tar.gz。tar.gz是一种常见的文件打包和压缩格式,通常用于...

    Galaxy Forces MMORPG-开源

    《Galaxy Forces MMORPG-开源》是一款基于网络的大型多人在线角色扮演游戏,允许玩家扮演宇宙中的英雄,探索浩渺星海,同时建设和发展自己的星际殖民地。这款游戏的独特之处在于其开源特性,意味着游戏代码对公众...

    Simscape-Multibody-Contact-Forces-Library:接触力实例和资料库

    如果您需要在自己的示例中包含该库,建议您仅在子文件夹Core中使用项目Contact_Forces_Core.prj。 您可以直接使用它,也可以像在本项目中一样将其包含在“参考项目”中。 使用此库的一般方法: 识别系统中在仿真...

    VR-Forces Migration Guide

    VR-Forces Migration Guide 本Migration Guide旨在帮助用户迁移到VR-Forces Version 4.7。该指南将指导用户完成迁移过程,并提供了相关的技术支持。 首先,VR-Forces是由VT MAK开发的一款虚拟现实软件,主要用于...

    forces-of-attraction

    吸引力 一个可视化快速约会实验结果的网站。 无需其他步骤即可在浏览器中查看。 最佳尺寸为1280x1280px,因此请根据您的显示器随意放大或缩小。项目结构我们的文件布局实际上与整个课程中为作业提供的模板相同。...

    Competitive-Programming:回购一些针对Code-Forces的解决方案

    在竞争性编程的世界里,Code-Forces是一个非常知名的在线平台,它提供了各种难度级别的算法题目,供程序员们提升自己的编程技巧和问题解决能力。"Competitive-Programming:回购一些针对Code-Forces的解决方案"这个...

    forces-and-motion-basics:“力与动

    力与运动:基础知识“ Force and Motion:Basics”是HTML5中的教育模拟,由科罗拉多大学博尔德分校的提供。 有关此模拟的说明,相关资源以及指向已发布版本的链接,。尝试一下! 文献资料是PhET仿真开发的最完整指南...

    VR-Forces用户指南

    ### VR-Forces用户指南:MAK公司VR-Forces 4.0.4 版本详析 #### 概览 《VR-Forces用户指南》是MAK公司为VR-Forces 4.0.4版本所编撰的官方用户手册。此文档详细介绍了VR-Forces软件的功能、操作流程、以及如何充分...

    Experimental study of needle-tissue interaction forces.pdf

    Experimental study of needle-tissue interaction forces: effect of needle geometries, insertion methods and tissue characteristics. it used to study the needle insertion force and the influence of ...

    Police Forces - free Ego Shooter-开源

    《Police Forces - 开源Ego Shooter游戏详解》 在当今的游戏世界中,开源软件逐渐崭露头角,其中Police Forces是一款备受关注的开源第一人称射击(FPS)游戏,专为Linux和Windows用户设计。这款游戏以其独特的设计...

Global site tag (gtag.js) - Google Analytics