当前位置:网站首页>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;
}
边栏推荐
- C语言的编译和预处理
- Icc2 use report_ Placement check floorplan
- What are the open earphones? Four types of air conduction earphones with excellent sound quality are recommended
- Problems of font modification and line spacing in word automatic directory
- What's a good gift for your girlfriend on the Chinese Valentine's day in 2022? Practical and beautiful gift recommendation
- [PTA----树的遍历]
- 【实现简易版扫雷小游戏】
- 2022-06-07 responsebodyadvice caused the spring frame problem in swagger
- 【学习笔记】工具
- Leetcode 刷题日记 剑指 Offer II 047. 二叉树剪枝
猜你喜欢

气传导蓝牙耳机哪个好、气传导蓝牙耳机排行榜

MySQL安装与使用

Development of Quantitative Trading Robot System

Development of clip arbitrage / brick carrying arbitrage system

QT custom sliding button (beautiful and easy to use)

【无标题】

What is the best and most cost-effective open headset recommended

关于时间复杂度,你不知道的都在这里

小程序创建组件

2022-05-24 use of spiel
随机推荐
valgrind工具
七夕礼物送女生什么好?颜值在线又有心意的礼物推荐
Listener
费马小定理
气传导蓝牙耳机怎么样、最值得入手的气传导耳机
刷题记录----二叉树的层序遍历
[PTA----树的遍历]
OJ 1045 反转然后相加
Combine multiple ICs calendars into a single ICs calendar
万字归纳总结并实现各大常用排序及性能对比
当前学习进度
【学习笔记】进程创建
刷题记录----哈希表
OJ 1089 春运
【C笔记】数据类型及存储
七夕送女朋友什么礼物好?不会送礼的男生速看!
QT painting event - set background picture
夹子套利/搬砖套利系统开发
Pyppeteer is recognized to bypass detection
OJ 1129 分数矩阵