1104 Sum of Number Segments
题意:
给出n个不大于1.0的小数序列,如{ 0.1, 0.2, 0.3, 0.4 },则共有10个分片(0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4) (0.3) (0.3, 0.4) and (0.4)。现要求计算每个分片之和,即0.1 + 0.3 + 0.6 + 1.0 + 0.2 + 0.5 + 0.9 + 0.3 + 0.7 + 0.4 = 5.0.
思路:数学题,找规律
a[i]
|
0.1
|
0.2
|
0.3
|
0.4
|
0.5
|
在a[i]左侧的个数(包括a[i]本身)
|
1
|
2
|
3
|
4
|
5
|
在a[i]右侧的个数(包括a[i]本身)
|
5
|
4
|
3
|
2
|
1
|
下标i
|
1
|
2
|
3
|
4
|
5
|
#include <stdio.h> int main() { int n; ,tmp; scanf("%d",&n); ;i<=n;i++){ scanf("%lf",&tmp); //sum+=tmp*(i*(n-i+1));//错误 语句1 sum+=tmp*i*(n-i+);//正确 } printf("%.2f\n",sum); ; }
1104 Sum of Number Segments的更多相关文章
- PAT 甲级 1104 sum of Number Segments
1104. Sum of Number Segments (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Pen ...
- PAT甲级——1104 Sum of Number Segments (数学规律、自动转型)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90486252 1104 Sum of Number Segmen ...
- 1104 Sum of Number Segments(20 分)
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...
- PAT 甲级 1104. Sum of Number Segments (20) 【数学】
题目链接 https://www.patest.cn/contests/pat-a-practise/1104 思路 最容易想到的一个思路就是 遍历一下所有组合 加一遍 但 时间复杂度 太大 会超时 ...
- PAT 1104 Sum of Number Segments
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...
- PAT (Advanced Level) 1104. Sum of Number Segments (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲题题解-1104. Sum of Number Segments (20)-(水题)
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- 【PAT甲级】1104 Sum of Number Segments (20 分)
题意:输入一个正整数N(<=1e5),接着输入N个小于等于1.0的正数,输出N个数中所有序列的和. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC ...
- PAT1107:Sum of Number Segments
1104. Sum of Number Segments (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Pen ...
随机推荐
- Windows批量添加和删除IP
随着天气变冷了,好多小伙伴都开始变懒了,都想用最快的方式完成任务 下面给大家介绍一下Windows批量添加和删除IP的办法 (1)批量添加IP 直接在CMD下边运行下边命令. for /l %i in ...
- shell中嵌套执行expect命令实例(利用expect实现自动登录)
expect是 #!/bin/bashpasswd='123456'/usr/bin/expect <<EOFset time 30spawn ssh root@192.168.76.10 ...
- 出现GC overhead limit exceeded 的解决方案
当我在使用MyEclispe IDE创建Maven项目的时候出现 "An internal error occurred during: “Build Project”. GC overh ...
- js写出斐波那契数列
斐波那契数列:1.1.2.3.5.8.13.21.34.…… 函数: 使用公式f[n]=f[n-1]+f[n-2],依次递归计算,递归结束条件是f[1]=1,f[2]=1. for循环: 从底层向上运 ...
- 井眼轨迹的三次样条插值 (vs + QT + coin3d)
井眼轨迹数据的测量值是离散的,根据某些测斜公式,我们可以计算出离散的三维的井眼轨迹坐标,但是真实的井眼轨迹是一条平滑的曲线,这就需要我们对测斜数据进行插值,使井眼轨迹变得平滑,我暂时决定使用三次样条进 ...
- docker安装 之 ---CentOS 7 系统脚本自动安装
[使用脚本自动安装] 在测试或开发环境中Docker官方为了简化安装流程,提供了一套便捷的安装脚本,CentOS系统上可以使用这套脚本安装: $ curl -fsSL get.docker.com - ...
- ZOJ - 3430 ac自动机
这题主要就是解码过程很恶心,不能用char存,一共wa了20发 题意:先给n串加密后的字符,然后m串加密后的字符,解码之后求n对应每个m的匹配数,很显然的ac自动机 加密过程是先用对应ascii表的标 ...
- hzau 1207 Candies
1207: Candies Time Limit: 2 Sec Memory Limit: 1280 MBSubmit: 223 Solved: 31[Submit][Status][Web Bo ...
- iOS 检查指定日期是否在当前日期之前
iOS检查指定日期是否在当前日期之前, 直接上代码: - (BOOL)checkProductDate: (NSString *)tempDate { NSDateFormatter *dateFor ...
- element-ui树结构懒加载
在实际项目中,往往树结构数据量较大,这时树节点必须懒加载 element-ui树的懒加载: <div style="width:100%;height:420px;overflow: ...