1104. Sum of Number Segments (20)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CAO, Peng

Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence {0.1, 0.2, 0.3, 0.4}, we have 10 segments: (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) (0.4).

Now given a sequence, you are supposed to find the sum of all the numbers in all the segments. For the previous example, the sum of all the 10 segments is 0.1 + 0.3 + 0.6 + 1.0 + 0.2 + 0.5 + 0.9 + 0.3 + 0.7 + 0.4 = 5.0.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N, the size of the sequence which is no more than 105. The next line contains N positive numbers in the sequence, each no more than 1.0, separated by a space.

Output Specification:

For each test case, print in one line the sum of all the numbers in all the segments, accurate up to 2 decimal places.

Sample Input:

4
0.1 0.2 0.3 0.4

Sample Output:

5.00

思路

题目要求求所有子集的和。

1.第i个数在所有子集中出现的次数为(N - i + 1) * i;
2.循环求和就行 代码
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
int main()
{
int N;
while(cin >> N)
{
vector<double> nums(N + 1);
double sum = 0;
for(int i = 1;i <= N;i++)
{
cin >> nums[i];
sum += nums[i] * (N - i + 1) * i;
}
cout << fixed << setprecision(2) << sum << endl;
}
}

  

PAT1107:Sum of Number Segments的更多相关文章

  1. PAT Sum of Number Segments[数学问题][一般]

    1104 Sum of Number Segments(20 分) Given a sequence of positive numbers, a segment is defined to be a ...

  2. PAT 甲级 1104 sum of Number Segments

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

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

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

  4. PAT_A1104#Sum of Number Segments

    Source: PAT A1104 Sum of Number Segments (20 分) Description: Given a sequence of positive numbers, a ...

  5. PAT A1104 Sum of Number Segments (20 分)——数学规律,long long

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

  6. A1104. Sum of Number Segments

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

  7. 1104 Sum of Number Segments(20 分)

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

  8. PAT 1104 Sum of Number Segments

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

  9. 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​​ ...

随机推荐

  1. Android安全机制浅谈-android学习之旅(80)

    由于Android安全机制存在,使得漏洞利用有一些困难. ASLR:即地址空间格局随机化.ASLR使得加载程序时不使用固定的基址加载,防止攻击者直接定位攻击代码位置,从而阻止溢出攻击 NX:(No e ...

  2. Unable To Import Or Enter Sale Order - ORA-20001: APP-FND-01564: ORACLE error - 1422 in get_seq_info

    In this Document   Symptoms   Cause   Solution APPLIES TO: Oracle Order Management - Version 12.0.4 ...

  3. ThreadLocal深入理解 修订版

    本文是传智博客多线程视频的学习笔记. 原版本见 http://blog.csdn.net/dlf123321/article/details/42531979 ThreadLocal是一个和线程安全相 ...

  4. 仿百度壁纸客户端(六)——完结篇之Gallery画廊实现壁纸预览已经项目细节优化

    仿百度壁纸客户端(六)--完结篇之Gallery画廊实现壁纸预览已经项目细节优化 百度壁纸系列 仿百度壁纸客户端(一)--主框架搭建,自定义Tab + ViewPager + Fragment 仿百度 ...

  5. LeetCode之“字符串”:Restore IP Addresses

    题目链接 题目要求: Given a string containing only digits, restore it by returning all possible valid IP addr ...

  6. ruby写一个文件内容相似性比较的代码

    1.相似度定义 我们定义,则,我们设,则,|C|=s,则相似度p=,p(0,1) 2.相似度检测算法设计 算法设计: 定义4个字符为一个字符串,将T1,T2分割成若干字符串,若剩余字符不足4个,则以空 ...

  7. 使用Owin的WebApi,并分离Controllers

    1.新建空白web项目 2.添加新建项=>OWIN Startup类(此时会自动下载owin,放在Packages里) 3.在Startup中输入 public void Configurati ...

  8. FFPLAY的原理(三)

    播放声音 现在我们要来播放声音.SDL也为我们准备了输出声音的方法.函数SDL_OpenAudio()本身就是用来打开声音设备的.它使用一个叫做SDL_AudioSpec结构体作为参数,这个结构体中包 ...

  9. Activex、OLE、COM、OCX、DLL之间有什么区别?

    来源:http://www.blogjava.net/Jack2007/archive/2008/04/27/196392.html         熟悉面向对象编程和网络编程的人一定对ActiveX ...

  10. win10 下安装mysql服务器社区版本mysql-5.7.22-winx64

    下载 下载: http://dev.mysql.com/downloads/mysql/ 解压到C盘 添加环境变量path 添加环境变量 右击我的电脑->属性->高级系统设置->高级 ...