题目链接

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. SVN环境搭建详解

      SVN服务器搭建和使用(一) Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网 ...

  2. 状态压缩DP常遇到的位运算

    位操作一共有6种形式:<<,>>,&,|,^,~; 1.左移操作符<<:左移操作符将整数的二进制向左移若干位,将最高若干位挤掉,并在低位补0 如: ; // ...

  3. linux下怎样对串口编程

    Linux操作系统从一開始就对串行口提供了非常好的支持,本文就Linux下的串行口通讯编程进行简单的介绍. 串口简单介绍串行口是计算机一种经常使用的接口.具有连接线少.通讯简单.得到广泛的使用. 经常 ...

  4. 2016.7.5 如何在maven中添加所需依赖(只知道jar包的部分名字的情况)

    (1)进入官网仓库 http://mvnrepository.com/ (2)输入需要的jar包名 比如这里的jota-time (3)寻找需要的版本,并选取需要的版本 (4)复制需要的maven依赖 ...

  5. Ubuntu下的计划任务 -- cron的基本知识

    下面不完全: 参考:http://blog.csdn.net/cuker919/article/details/6336457 cron是一个Linux下的后台进程,用来定期的执行一些任务.因为我用的 ...

  6. 关于阿里 weex 的使用与案例

    1. 阿里宣布开源Weex http://mp.weixin.qq.com/s?__biz=MzA4MjA0MTc4NQ==&mid=504089541&idx=1&sn=3a ...

  7. prop()方法和attr()方法以及区别

    prop()方法: prop() 方法设置或返回被选元素的属性和值. 当该方法用于返回属性值时,则返回第一个匹配元素的值. 当该方法用于设置属性值时,则为匹配元素集合设置一个或多个属性/值对. 注意: ...

  8. PHP session回收机制(转)

    由于PHP的工作机制,它并没有一个daemon线程,来定时地扫描session信息并判断其是否失效.当一个有效请求发生时,PHP会根据全局变量 session.gc_probability/sessi ...

  9. nodejs初学-----helloworld

    近期紧锣密鼓的学习了下nodejs(之前在学php.算入门了吧,可是时间关系,还没写文章,兴许要搞安卓和大数据,总之比較忙哈,计划上php要排到后面了,还请广大小伙伴不要着急) 先抄一句:Node.j ...

  10. Android推断是否有sd卡

    推断手机上是否有SD卡存在.作为经常用法,写到工具类里,用时直接调用.代码例如以下: public static boolean hasSdcard(){ String state = Environ ...