HDU5879(打表)
发布日期:2021-06-24 06:47:42 浏览次数:5 分类:技术文章

本文共 1361 字,大约阅读时间需要 4 分钟。

Cure

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 293    Accepted Submission(s): 96

Problem Description

Given an integer 
n, we only want to know the sum of 1/k2 where k from 1 to n.
 

 

Input

There are multiple cases.
For each test case, there is a single line, containing a single positive integer 
n
The input file is at most 1M.
 

 

Output

The required sum, rounded to the fifth digits after the decimal point.
 

 

Sample Input

1
2
4
8
15
 

 

Sample Output

1.00000
1.25000
1.42361
1.52742
1.58044
 

 

Source

 
n没有给出范围,意思就是默认无限大。。。。。比赛时被坑了,不停RE。
1 //2016.9.17 2 #include 
3 #include
4 5 using namespace std; 6 7 double sum[54000]; 8 9 int main()10 {11 int n;12 double ans;13 ans = 0;14 sum[0] = 0;15 for(int i = 1; i <= 53000; i++)16 {17 ans += (1.0/i)*(1.0/i); 18 sum[i] = ans;19 }20 string s;21 while(cin>>s)22 {23 int len = s.length();24 n = 0;25 for(int i = 0; i < len; i++)26 {27 n = n*10+s[i]-'0';28 if(n > 120000)break;29 }30 if(n >= 110291)ans = 1.64493;31 else if(n >= 52447)ans = 1.64492;32 else ans = sum[n];33 printf("%.5lf\n", ans);34 }35 36 return 0;37 }

 

转载于:https://www.cnblogs.com/Penn000/p/5879533.html

转载地址:https://blog.csdn.net/weixin_30896763/article/details/97648981 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:MVC3中 ViewBag、ViewData和TempData的使用和区别
下一篇:如何在DOCKER环境中使用DB2

发表评论

最新留言

很好
[***.229.124.182]2024年04月05日 00时54分14秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

C++核心准则C.48:如果构造函数需要用常数初始化成员,使用类内初始化器更合适 2019-04-28
C++核心准则C.49:构造函数中应该做的是初始化而不是赋值 2019-04-28
C++核心准则C.50:如果在构造过程中需要“虚行为”,使用工厂函数 2019-04-28
C++核心准则C.51:使用委托构造函数实现所有构造函数的共通动作 2019-04-28
C++核心准则C.52:合理使用继承的构造函数 2019-04-28
基于Chrome浏览器的前端调试 2019-04-28
第1章 Ext JS介绍与快速入门[1/4] 2019-04-28
第1章 Ext JS介绍与快速入门[2/4] 2019-04-28
Python:Flask部署Nginx、gunicorn、gevent、flask、supervisor 2019-04-28
程序员之路:mysql表级约束与列级约束_彭世瑜_新浪博客 2019-04-28
程序员之路:mysql修改数据表_彭世瑜_新浪博客 2019-04-28
程序员之路:C语言内存不足已停止工作_彭世瑜_新浪博客 2019-04-28
程序员之路:MySQL操作数据表记录_彭世瑜_新浪博客 2019-04-28
程序员之路:Github版本控制入门_彭世瑜_新浪博客 2019-04-28
程序员之路:MySQL子查询与连接_彭世瑜_新浪博客 2019-04-28
程序员之路:为github项目建立网页_彭世瑜_新浪博客 2019-04-28
Python编程:sublime编辑器python开发必装插件_彭世瑜_新浪博客 2019-04-28
程序员之路:Emmut语法_彭世瑜_新浪博客 2019-04-28
程序员之路:sublime使用技巧_彭世瑜_新浪博客 2019-04-28
Python编程:创建Django项目_彭世瑜_新浪博客 2019-04-28