zoukankan      html  css  js  c++  java
  • Codeforces Round B. Buttons

    Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.

    Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.

    Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.

    Input

    A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.

    Output

    In a single line print the number of times Manao has to push a button in the worst-case scenario.

    Sample test(s)
    input
    2
    
    output
    3
    
    input
    3
    
    output
    7
    
    Note

    Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        int s=0;
        for(int i=1;i<=n;i++)
        {
            s+=1+(n-i)*i;
        }
        cout<<s<<endl;
    }
  • 相关阅读:
    python——协程
    解读python中SocketServer源码
    python——初识socket
    python的类和对象——类的静态字段番外篇
    python的类和对象——类成员番外篇
    python的类和对象——进阶篇
    初识python中的类与对象
    python中lambda表达式应用
    python——挖装饰器祖坟事件
    python的基础类源码解析——collection类
  • 原文地址:https://www.cnblogs.com/wangmenghan/p/5751207.html
Copyright © 2011-2022 走看看