Written by razrlele
20:42 January 15, 2015
我觉得应该算是数论的题目?
关键在于找规律, 比如输入为 6 2
遍历所有的输出
1 2 3 4 5 6 |
6 6 6 6 6 6 5 5 5 5 5 6 4 4 4 4 5 6 3 3 3 4 5 6 2 2 3 4 5 6 1 2 3 4 5 6 |
从此可以发现最终的输出其实是一个棱长为m的n方体, 一层一层向外面包, 故第i层的元素个数即为 i^n-(i-1)^n, 然后第i层的元素都为i, 然后总的元素个数是m^n, 注意最后求的时候不能直接算m^n, 不然会溢出, 换成算(i/m)^n即可.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
/******************************************************** * File Name: 454C.cpp * Author: razrLeLe * Mail: razrlele@outlook.com * Homepage: https://yueyu.io * Created Time: Thu 15 Jan 2015 06:14:05 PM CST ******************************************************/ #include "vector" #include "set" #include "deque" #include "queue" #include "algorithm" #include "functional" #include "iostream" #include "cstdio" #include "cmath" #include "cstdlib" #include "string" #include "cstring" #include "string.h" #include "map" #include "cctype" #include "list" #include "stack" using namespace std; #define INF 0x3f3f3f3f #define LOCAL #define REP(i, start, end) for(i = (start); i <= (end); ++i) double ans; int m, n; int main() { #ifdef LOCAL freopen("/home/razrlele/build/data.txt", "r", stdin); freopen("/home/razrlele/build/out.txt", "w", stdout); #endif double i; while(cin >> m >> n) { ans = 0; REP(i, 1, m) ans += i*(pow(i/m, n) - pow((i-1)/m, n)); printf("%.12lf\n", ans); } return 0; } |