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 ...
随机推荐
- 使用Shell脚本查找程序对应的进程ID,并杀死进程
#!/bin/sh NAME='shell.php' echo $NAME ID=`ps -ef | grep "$NAME" | grep -v "$0" | ...
- streambase log(log4j和logback)
需要注意的是:当streambase servce 由window service 方式启动时,logback日志机制就不起作用了需要做下配置处理 https://support.tibco.com/ ...
- Apache Phoenix的Array类型
Apache Phoenix支持JDBC ARRAY类型,任何原生的数据类型就可以在ARRAY中使用.下面我介绍一下在创建的表中使用ARRAY类型. 先看一下创建表的SQL语句: CREATE TAB ...
- 让外界可以访问电脑上的网站的几种方式——花生壳,域名,IIS(待)
前话: 每次“养大“一个网站,都有种骄傲地想秀给朋友们看的冲动. 之前可能是困于电脑,实在不方便. 现在,不用克制了! 该秀就秀,能装逼就装逼. 养大孩子就该拉出来秀秀,见见世面. 正题:这次实习,我 ...
- 循环插入一条数据的sql写法
DECLARE @i INTSET @i = 1WHILE @i > 0 BEGIN DECLARE @TransportFormMstID BIGINT; DECLARE @TradeOrde ...
- 使用Navicat进行数据库自动备份
今天经历一次数据库丢库事件,顿时觉得定时备份数据库很重要. 但是每天自己手动备份实在是太麻烦了,于是乎,想到用计划任务进行每天定时自动备份. 发现Navicat自带就有备份 还可以直接计划任务,贼方 ...
- 美化tp5.1跳转提示
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- JavaScrip 原生多文件上传及预览 兼容多浏览器
JavaScrip 原生多文件上传及预览 兼容多浏览器 html代码块 <div class="container"> <label>请选择一个图像文件:& ...
- jQuery download file
jQuery.download = function (url, method, p, c, e, i, o, goodsType, reciveUser, suplier) { jQuery('&l ...
- JavaScript数组和函数的使用
数组 数组:一个有顺序,有长度的数据集合 作用:存储大量数据 一.数组的定义 1.构造函数法:使用构造函数法的时候,都会使用new关键字 var arr=new Array(): 当长度为0 的时候, ...