我是靠谱客的博主 传统大门,这篇文章主要介绍codeforces 268B Buttons,现在分享给大家,希望可以做个参考。

B. Buttons
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
Input
复制代码
1
2
Output
复制代码
1
3
Input
复制代码
1
3
Output
复制代码
1
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.



这道题题意是找出一个按对按钮的最坏情况

例1:

2个按钮:

正确顺序:1 2

所以

   2

1 2

三下

3个按钮:

正确顺序:1 2 3

所以

   2

      3

1    3

1 2 3

七下

四个按钮:

正确顺序:1 2 3 4

所以

   2

      3

          4

1    3

1       4

1 2    4

1 2 3 4

十四下

大概就这思路

AC:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ans=0;
    int s=n;
    for(int i=1;n>=1;i++)
    {
        ans+=i*(n-1);
        n--;
    }
    cout<<ans+s;
}



最后

以上就是传统大门最近收集整理的关于codeforces 268B Buttons的全部内容,更多相关codeforces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(81)

评论列表共有 0 条评论

立即
投稿
返回
顶部