解题思路:
换底公式
a = lg(n)/log(m)
注意事项:
参考代码:
#include <iostream> #include <algorithm> #include <stdio.h> #include <math.h> #include <vector> using namespace std; vector<int> arr; int solve(int l, int r) { for (int i = l; i <= r; i++) arr[i] = log(arr[i])*1.0 / log(2) + 1; int ans = 0; for (vector<int>::iterator it = arr.begin(); it < arr.end(); it++) ans += *it; return ans; } int main(void) { int n, m; cin >> n >> m; arr.push_back(0); for (int i = 1; i <= n; i++) { int temp = 0; cin >> temp; arr.push_back(temp); } for (int i = 1; i <= m; i++) { int l, r; cin >> l >> r; cout << solve(l, r) << endl; } return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:1222 |
C语言程序设计教程(第三版)课后习题8.2 (C语言代码)浏览:5228 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:464 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:697 |
A+B for Input-Output Practice (V) (C语言代码)浏览:459 |
字符逆序 (C语言代码)浏览:612 |
理财计划 (C语言代码)浏览:465 |
整数平均值 (C语言代码)浏览:777 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:602 |
C二级辅导-计负均正 (C语言代码)浏览:634 |