codeforces Buttons 数学公式构建
2014-04-30 13:46
417 查看
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
output
input
output
这样的题目虽然不难,但是要构建个数学公式还真不容易的。
做多了,居然有感觉了,可以感知到大概公式是什么样的,然后验证它。
本题公式就是:
S = n + (n-1) + (n-2) * 2 + (n - 3) * 3 ...
至于怎么想出来的?
模拟一下他的操作,然后得出数列,最后从数列中总结出规律,然后写出去公式。
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
这样的题目虽然不难,但是要构建个数学公式还真不容易的。
做多了,居然有感觉了,可以感知到大概公式是什么样的,然后验证它。
本题公式就是:
S = n + (n-1) + (n-2) * 2 + (n - 3) * 3 ...
至于怎么想出来的?
模拟一下他的操作,然后得出数列,最后从数列中总结出规律,然后写出去公式。
#include <iostream> using namespace std; void Buttons() { int n = 0; cin>>n; int ans = n; int c = 1; while (--n) { ans += n * c; c++; } cout<<ans; }
相关文章推荐
- codeforces 650 C. Watchmen(数学公式)
- Codeforces 758C Unfair Poll 数学推导,公式
- Codeforces 513C Second price auction 数学公式求期望
- CodeForces 635C XOR Equation 数学 公式
- Codeforces 839D Winter is here【容斥原理+数学公式】
- codeforces 616E Sum of Remainders(数学公式转化 较难)
- codeforces 616E Sum of Remainders 数学公式转化
- CodeForces 659 D. Bicycle Race(计算几何 + 数学公式)
- CodeForces 630Q Pyramids(数学公式)
- Codeforces 534C Polycarpus' Dice(数学,公式推导)
- Codeforces 615D Multipliers(数学推公式)
- CodeForces 469A. I Wanna Be the Guy(数学)
- Markdown中插入数学公式的方法
- 4000 CodeForces 810A Straight <<A>> 【数学】【模拟】
- codeforces 895E Eyes Closed 线段树 期望 数学
- 几个有用的数学公式 for ActionScript 3
- HDOJ 4311 —— 排序&数学公式
- Markdown中插入数学公式的方法
- Codeforces 622F 「数学数论」「数学规律」
- Codeforces 595B Pasha and Phone 【数学计数】