zzuli2183—分步打表
来源:互联网 发布:手机免费炒股软件 编辑:程序博客网 时间:2024/05/22 10:41
河南省第五次多校联萌B题
2183: 就是签到题XD
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 521 Solved: 78
SubmitStatusWeb Board
Description
In mathematics, we suppose that f(1)=1, f(i)-f(i-1)=1/i, (2<=i<=n)
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case starts with a line containing an integer n (2 ≤ n ≤10^7).
Output
For each case, print the case number and the value of f(n). The answer should be rounded to 10 decimal places.
Sample Input
3
2
3
4
Sample Output
Case 1: 1.5000000000
Case 2: 1.8333333333
Case 3: 2.0833333333
HINT
Source
河南省多校连萌(五)
SubmitStatusWeb Board
解题思路:
分步打表,把10000000分为50个一组,整50的存一次,打完表之后每一次最多循环50次·。(受到大佬的启发才知道怎么做的)
下面是代码:
#include<stdio.h>#define N 10000000double f[N/50+3];void db();int main(){ int t,n,i; db(); scanf("%d",&t); int k=0; while(t--) { k++; scanf("%d",&n); double v=f[n/50]; for(i=n/50*50+1;i<=n;i++) v+=1.0/double(i); printf("Case %d: %.10lf\n",k,v); } return 0;}void db(){ double s=1.0; int i; f[1]=1.0; for(i=2;i<=N;i++) { s+=1/double(i); if(i%50==0) f[i/50]=s; }}/************************************************************** Problem: 2183 User: 201605050139 Language: C++ Result: Accepted Time:126 ms Memory:2452 kb****************************************************************/
上面的代码能交过c++交不过zzuli的c,下面这个能交过c
#include<stdio.h>#define N 10000003double f[N/50+3];void db();int main(){ int t,n,i; db(); double c; scanf("%d",&t); int k=0; while(t--) { k++; scanf("%d",&n); double v=f[n/50]; for(i=n/50*50+1;i<=n;i++) { c=i; v+=1.0/c; } printf("Case %d: %.10lf\n",k,v); } return 0;}void db(){ double s=1.0; int i; double c; f[1]=1.0; for(i=2;i<=N;i++) { c=i; s+=1.0/c; if(i%50==0) f[i/50]=s; }}
- zzuli2183—分步打表
- R—self同类分步
- Stream单表复制:分步实施,本地捕获
- 打表
- 打表
- 打表
- 打表
- 打表
- 打表
- zzuli2183: 就是签到题XD(欧拉常数)
- BNUOJ 52297 Coins——打表
- sdut3257——Square Number(打表)
- sdut3257——Cube Number(打表)
- 【分步处理的妙处】 校练习赛Problem D——Dinner Hall (附judge地址)
- Java学习之道:弹球游戏分步解析(二)——让小球飞
- Sql 分步 事务 配置
- 俄罗斯方块分步程序
- Struts分步表单提交
- lingo导入excel数据具体实现步骤
- Java Bean登录页面实现
- C++静态成员函数访问非静态成员的几种方法
- 2017.08.26 360笔试题:小明卖粉笔
- Linux下配置NDK、JDK环境变量
- zzuli2183—分步打表
- java 寻找数组中第k大的值
- 内核对象(2)之跨越边界进程共享内核对象
- spring data jpa懒加载session失效:OpenEntityManagerInViewFilter 取代OpenSessionInViewFilter
- KeyError: ‘SQLALCHEMY_TRACK_MODIFICATIONS’ 的错误问题
- maven webapp的标准pom.xml配置
- 零
- numpy 多个随机整数生成
- 8月英语总结