题目链接

https://www.patest.cn/contests/pat-a-practise/1104

思路

最容易想到的一个思路就是 遍历一下所有组合 加一遍

但 时间复杂度 太大 会超时

其实可以发现 每个数字的出现频率是有规律的

比如

4

0.1 0.2 0.3 0.4

这组数据

0.1 4

0.2 6

0.3 6

0.4 4

然后 出现次数 刚好满足 (i + 1) * (n - i) 这个公式

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll; const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-6; const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7; int main()
{
int n;
double num;
scanf("%d", &n);
double sum = 0.0;
for (int i = 0; i < n; i++)
{
scanf("%lf", &num);
sum += num * (i + 1) * (n - i);
}
printf("%.2lf\n", sum);
}

PAT 甲级 1104. Sum of Number Segments (20) 【数学】的更多相关文章

  1. PAT 甲级 1104 sum of Number Segments

    1104. Sum of Number Segments (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Pen ...

  2. PAT甲级——1104 Sum of Number Segments (数学规律、自动转型)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90486252 1104 Sum of Number Segmen ...

  3. PAT Advanced A1104 Sum of Number Segments (20) [数学问题]

    题目 Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For e ...

  4. 【PAT甲级】1104 Sum of Number Segments (20 分)

    题意:输入一个正整数N(<=1e5),接着输入N个小于等于1.0的正数,输出N个数中所有序列的和. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC ...

  5. PAT甲级——A1104 Sum of Number Segments【20】

    Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ ...

  6. PAT (Advanced Level) 1104. Sum of Number Segments (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  7. PAT甲题题解-1104. Sum of Number Segments (20)-(水题)

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  8. PAT甲级——A1104 Sum of Number Segments

    Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...

  9. PAT 甲级 1019 General Palindromic Number(20)(测试点分析)

    1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...

随机推荐

  1. 关于Web应用和容器的指纹收集以及自动化软件的制作

    一次对Web应用的渗透,九成都是从信息收集开始,所以信息收集就显得尤为重要.关键信息的收集可以使你在后期渗透的时候更加的得心应手,把渗透比喻成走黑暗迷宫的话,那信息收集可以帮你点亮迷宫的大部分地图. ...

  2. glsl镜面水倒影的实现[转]

    http://blog.sina.com.cn/s/blog_78ea87380101ejbf.html 使用两相机,一个master相机, 主要负责场景的渲染, 另一个rtt相机, 和master相 ...

  3. 15、Spring Boot使用Druid和监控配置【从零开始学Spring Boot】

    转载:http://blog.csdn.net/linxingliang/article/details/52001740目录(?)[-] 1添加Maven依赖 或jar包 2配置数据源相关信息 3 ...

  4. AutoCAD如何移动零件和缩放零件图

    如下图所示,我想要把这个零件放大并移动到图纸的中央,先全部选中这个零件,方法是在左上角点一下,然后拖出一个矩形包围整个零件   然后点击右侧的缩放命令,底部的命令栏变成指定基点的时候,在这个图纸的右上 ...

  5. 微信小程序 - 传参的几种方式

    1. navigator navigator?第一参数&第二参数 .... 在传递页面的options可以拿到传递过来的参数 <navigator url='start-test/sta ...

  6. vue2.X computed 计算属性

    需求:数据msg值为12345,我们现在需要反向显示成54321. 1.在模板中绑定表达式是非常便利的,但是它们实际上只用于简单的操作.在模板中放入太多的逻辑会让模板过重且难以维护.例如: <! ...

  7. Shell脚本之:while

    while循环用于不断执行一系列命令,也用于从输入文件中读取数据:命令通常为测试条件.其格式为: while command do Statement(s) to be executed if com ...

  8. Node.js学习笔记(5)——关于child_process模块

    child_process是node一个比较重要的模块,通过它可以实现创建多线程,来利用多核CPU. 这个模块提供了四个创建子进程的函数. spawn.exec.execFile.fork. spaw ...

  9. Spring学习十二----------Bean的配置之@ImportResource和@Value

    © 版权声明:本文为博主原创文章,转载请注明出处 @ImportResource -引入XML配置文件 @Value -从配置文件中获取值 实例 1.项目结构 2.pom.xml <projec ...

  10. 移动应用开发测试工具Bugtags集成和使用教程【转载】

    前段时间,有很多APP突然走红,最终却都是樱花一现.作为一个创业团队,突然爆红是非常难得的机会.然并卵,由于没有经过充分的测试,再加上用户的激增,APP闪退.服务器数据异常等问题就被暴露出来,用户的流 ...