/*
子序列的和(subsequence)
输入两个整数n<m<10^6,输出1/(n^2) + 1/((n+1)^2) + 1/((n+2)^2) 1/((n+3)^2) + ... + 1/((m)^2)
保留5位小数。输入包含多组数据,结束标记为n=m=0。提示:本题目有陷阱
样例输入:
2 4
65536 655360
样例输出:
Case 1:0.42361
Case 2:0.00001
*/ #include <iostream>
#include <math.h>
using namespace std; int main(){
int n, m, cases = 0;
double result = 0.0;
while(scanf("%d %d", &n, &m) == 2){
if((n == m) && ( m == 0)){
break;
} cases++;
result = 0.0;
for(int i = n; i< m; i++){
result += 1. / (long long)(pow(i, 2));//【key 1】10^6,范围;【key 2】1. 运用浮点数运算,否则会有精度损失
}
printf("Case %d: %.5f\n", cases, result);
} return 0;
}
/*
[input]
2 4
65536 655360
0 0
[output]
Case 1:0.42361
Case 2:0.00001
*/

【参考文献】

  刘汝佳.《算法竞赛入门经典》

  

[C++]2-4 子序列的和的更多相关文章

  1. 用python实现最长公共子序列算法(找到所有最长公共子串)

    软件安全的一个小实验,正好复习一下LCS的写法. 实现LCS的算法和算法导论上的方式基本一致,都是先建好两个表,一个存储在(i,j)处当前最长公共子序列长度,另一个存储在(i,j)处的回溯方向. 相对 ...

  2. codevs 1576 最长上升子序列的线段树优化

    题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...

  3. [LeetCode] Arithmetic Slices II - Subsequence 算数切片之二 - 子序列

    A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...

  4. [LeetCode] Is Subsequence 是子序列

    Given a string s and a string t, check if s is subsequence of t. You may assume that there is only l ...

  5. [LeetCode] Wiggle Subsequence 摆动子序列

    A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...

  6. [LeetCode] Increasing Triplet Subsequence 递增的三元子序列

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  7. [LeetCode] Distinct Subsequences 不同的子序列

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  8. 动态规划之最长公共子序列(LCS)

    转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...

  9. [Data Structure] LCSs——最长公共子序列和最长公共子串

    1. 什么是 LCSs? 什么是 LCSs? 好多博友看到这几个字母可能比较困惑,因为这是我自己对两个常见问题的统称,它们分别为最长公共子序列问题(Longest-Common-Subsequence ...

  10. 51nod1134(最长递增子序列)

    题目链接: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1134 题意: 中文题诶~ 思路: 直接暴力的话时间复杂度为 ...

随机推荐

  1. nodejs的某些api~(五) HTTP模块

    HTTP的模块是nodejs最重要的模块(应该是),最近在看HTTP权威指南,重新过了一遍http协议和web客户端.再来看这个http. HTTP构建于TCP之上,属于应用层协议,继承自tcp服务器 ...

  2. BZOJ 1996: [Hnoi2010]chorus 合唱队(区间dp)

    题目: https://www.lydsy.com/JudgeOnline/problem.php?id=1996 题解: 这题刚拿到手的时候一脸懵逼qwq,经过思考与分析(看题解),发现是一道区间d ...

  3. N球M盒

    N球,M盒,由于球是否相同,盒是否相同,盒是否可以为空,共2^3=8种: 1.球同,盒同,盒不可以为空Pm(N)--这符号表示部分数为m的N-分拆的个数,m是P的下标,为了好看我将大写的M弄成小写 2 ...

  4. win10 python3.5 自动补全设置

    https://www.cnblogs.com/lgh344902118/p/8521437.html # python startup file import readline import rlc ...

  5. R: 修改镜像、bioconductor安装及go基因富集分析

    1.安装bioconductor及go分析涉及的相关包 source("http://bioconductor.org/biocLite.R") options(BioC_mirr ...

  6. 第六节,TensorFlow编程基础案例-保存和恢复模型(中)

    在我们使用TensorFlow的时候,有时候需要训练一个比较复杂的网络,比如后面的AlexNet,ResNet,GoogleNet等等,由于训练这些网络花费的时间比较长,因此我们需要保存模型的参数. ...

  7. nginx 配置两个域名

    1.首先第一步安装: 参考:https://www.cnblogs.com/wyd168/p/6636529.html 启动: /usr/local/nginx/sbin/nginx -c /usr/ ...

  8. Luogu P2575 高手过招

    题目链接 \(Click\) \(Here\) 关键在于转换成阶梯\(Nim\)的模型.最开始把题目看错了,理解正确后发现棋子可以向后跳不止一位,那么就比较简单了. 这里把空格看做阶梯,棋子看做硬币, ...

  9. (链表) 83. Remove Duplicates from Sorted List

    Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...

  10. python自动化开发-[第十七天]-django的ORM与其他

    今日概要: 1.name别名 2.模版的深度查询 3.模版语言之filter 4.自定义过滤器,filter和simpletag的区别 5.orm进阶 扫盲:url的组成 URL:协议+域名+端口+路 ...