您的位置:首页 > 其它

Hdu-2156-分数矩阵 [水题]

2017-04-05 22:13 225 查看
题目传送门

只需要求上三角矩阵的和再乘2减去n。

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
using namespace std;
int main(void)
{
int n;
while (scanf("%d", &n))
{
if (n==0)
break;
double s=0,ss=0;
for (int i = 1; i <= n; i++)
{
ss = ss+1.0/i;
s = s + ss;
}
printf("%.2f\n",s*2-n);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: