当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
[哈希表基础知识]
2022-06-07 VI. log implementation
【无标题】
Antenna effect solution
OJ 1505 保险丝
正反斜杠笔记
[PTA----输出全排列]
What is hash? (development of Quantitative Trading Robot System)
【学习笔记】工具
OpenGL quick configuration method
STM32的IAP跳转相关bug经历
我的部署笔记
Explain the installation of MSDN 2015 and precautions
万字归纳总结并实现各大常用排序及性能对比
【动态规划--买卖股票的最佳时期系列2】
NFT数藏盲盒+模式系统开发
量化交易机器人系统开发
Listener
2022-06-07 responsebodyadvice caused the spring frame problem in swagger
当前学习进度









