UVA 11384 Help is needed for Dexter
2013-05-31 12:32
621 查看
给定序列1...n,每次可以选中序列几个数,然后同时减去相同到一个数,求把序列全部变成0所需要到最小次数.
做法是每次选择序列中最中间到位置到那个数,然后中间到最右边的区间到数全部减去这个值,如 1 2 3 4 5 6 选择4 减掉后得 1 2 3 0 1 2 这个序列其实跟1 2 3 是一样的.
一直这样到操作直到n变成0,复杂度为lgn
做法是每次选择序列中最中间到位置到那个数,然后中间到最右边的区间到数全部减去这个值,如 1 2 3 4 5 6 选择4 减掉后得 1 2 3 0 1 2 这个序列其实跟1 2 3 是一样的.
一直这样到操作直到n变成0,复杂度为lgn
#include <iostream> #include <cstdio> using namespace std; int n; int main(){ while(~scanf("%d", &n)){ int res = 0; while(n){ n /= 2; res++; } printf("%d\n", res); } return 0; }
相关文章推荐
- UVa 11384 Help is needed for Dexter
- UVa11384 - Help is needed for Dexter
- uva_11384_Help is needed for Dexter(貪心)
- Uva 11384 - Help is needed for Dexter
- UVa_11384_Help is needed for Dexter_贪心、二分最优的证明
- UVA 11384 - Help is needed for Dexter
- UVa 11384 Help is needed for Dexter
- D - Help is needed for Dexter UVA - 11384 (规律题)
- UVA 11384 - Help is needed for Dexter
- UVA11384—Help is needed for Dexter
- uva-----(11384)Help is needed for Dexter
- uva 11384 Help is needed for Dexter(模拟)
- uva - 11384 - Help is needed for Dexter(数学)
- uva 11384 - Help is needed for Dexter
- UVA 11384 Help is needed for Dexter
- UVA - 11384 Help is needed for Dexter
- uva 11384 正整数序列( Help is needed for Dexter)
- 【巧妙算法系列】【UVA 11384】 Help is needed for Dexter 正整数序列
- uva 11384 - Help is needed for Dexter
- UVA - 11384 Help is needed for Dexter ——递归