Codeforces #164 B. Buttons (数学
来源:互联网 发布:已定义两个字符数组ab 编辑:程序博客网 时间:2024/04/29 18:13
B. Buttons
time limit per test1 second
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.
A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.
In a single line print the number of times Manao has to push a button in the worst-case scenario.
2
3
3
7
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.
手动算了几组数据并没有发现什么规律23333(参考了下聚聚的blog
- 1 1
- 2 3
- 3 7
- 4 14
- 5 25
公式
sum = n + (n-1)*1 +(n-2)*2 + (n-3)*3 + …..
#include <stdio.h>int main(){ int n; while(~scanf("%d",&n)) { int sum = n; for(int i = 1;i <= n; i++) { sum += (n-i)*i; } printf("%d\n",sum); }return 0;}
- Codeforces #164 B. Buttons (数学
- Codeforces 268B Buttons
- CODEFORCES:B. Two Buttons
- Codeforces-268B-Buttons
- Codeforces-268b E Buttons
- CodeForces 520B【Two Buttons】
- Codeforces 520B. Two Buttons
- Codeforces 520B.Two Buttons
- Codeforces Round #164(Div. 2) B. Buttons【找规律】
- B. Two Buttons(Codeforces Round #295(div2))
- Codeforces Round #295 B. Two Buttons
- Codeforces 520B. Two Buttons spfa
- Codeforces 520 B Two Buttons BFS
- Codeforces 520B Two Buttons 【BFS】||【spfa】
- Codeforces 295 Div2 B.Two Buttons
- codeforces 520B Two Buttons BFS
- Codeforces 520B Two Buttons 题解
- CodeForces 520 B.Two Buttons(bfs)
- POJ 2559 Largest Rectangle in a Histogram(RMQ+二分)
- 结构型模式-适配器(adapter)
- Algorithm, Secret key and Protocol
- Leetcode——107. Binary Tree Level Order Traversal II
- redis主从数据库转换之后从库连接不上
- Codeforces #164 B. Buttons (数学
- Builder模式演义
- poj1101-The Game(BFS)
- Java—Eclipse
- 【约瑟夫环】Java实现:100个人开始从1开始报数,每当报数到3,报数3的人离开,求最后留下来人的位置。
- Http多线程下载文件的处理机制
- 如何使用VS2010打开VS2015的工程文件
- ADB命令最全总结
- Linux命令学习之---md5sum