当前位置:网站首页>OJ 1129 fraction matrix
OJ 1129 fraction matrix
2022-07-28 06:38:00 【JETECHO】
describe
We define the matrix as follows :
1/1 1/2 1/3
1/2 1/1 1/2
1/3 1/2 1/1
The elements on the diagonal of a matrix are always 1/1, The denominators of the fractions on both sides of the diagonal increase one by one .
Request the sum of this matrix .
Input
Input contains multiple sets of test data . Given integer per line N(N<50000), The representation matrix is N*N. When N=0 when , End of input .
Output
Output the answer , The result is reserved 2 Decimal place .
sample input 1
1
2
3
4
0
sample output 1
1.00
3.00
5.67
8.83
The topic is regular , First of all, on both sides of the diagonal are symmetry Of , also Quantity is decreasing Of , Denominator from 1~n The quantity is just decreasing , also The difference between two adjacent denominators 1, On the other side 1~1/n The number of n~1, Because of symmetry, we have to multiply everything except diagonal 2, That is, the number of data outside the diagonal is (n-i)*2, According to this rule, we can get the result .
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
while(cin>>n&&n)
{
double sum=n;
for(int i=1;i<n;i++)
{
sum+=((n-i)*2.0)/(i+1.0);
}
printf("%.2f\n",sum);
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Execjs call
What's a good gift for your girlfriend on Chinese Valentine's day? Boys who can't give gifts, look!
execjs 调用
夹子套利/搬砖套利系统开发
空气传导耳机哪个牌子好、备受好评的气传导耳机推荐
My notes
【C语言】字符串库函数介绍及模拟
Pyppeteer is recognized to bypass detection
刷题记录----反转链表(反转整个链表)
Get the current directory in QT
【学习笔记】进程创建
结构体、位段、联合体(共用体)的大小如何计算
【学习笔记】知识管理
Hugging face's problem record I
OJ 1018 报数游戏
【实现简易版扫雷小游戏】
[c语言]--一步一步实现扫雷小游戏
【自我救赎的开始】
OJ 1284 记数问题
QT solves the problem of rebuilding UI files every time they are modified







![[哈希表基础知识]](/img/8f/54a4780a02f81e5de3d92c25248e1e.png)
![[队列,栈的简单应用----包装机]](/img/bc/617b1eb35558c4f948018f593a1de5.jpg)
