1104 Sum of Number Segments(二刷)

英文题目:1104 Sum of Number Segments

中文题目:1049 数列的片段和

 1 #include<iostream>
 2 using namespace std;
 3
 4 int main() {
 5     int n;
 6     double t,sum = 0;
 7     cin>>n;
 8     for(int i = 0 ; i < n; ++i) {
 9         cin>>t;
10         sum += (i+1)*t*(n-i);
11     }
12     printf("%.2f\n",sum);
13     return 0;
14 }

原文地址:https://www.cnblogs.com/keep23456/p/12580495.html

时间: 2024-08-29 23:49:05

1104 Sum of Number Segments(二刷)的相关文章

1104. Sum of Number Segments (20)【数学题】——PAT (Advanced Level) Practise

题目信息 1104. Sum of Number Segments (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B 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)

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

本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90486252 1104 Sum of Number Segments (20 分) 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,

PAT 甲级 1104 Sum of Number Segments (20分)(有坑,int *int 可能会溢出)

1104 Sum of Number Segments (20分)   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

1104 Sum of Number Segments (20)

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

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

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; int n; double a[100000+10]; double b[100000+10]

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. 思路:数学题

[LeetCode OJ] Single Number之二 ——Given an array of integers, every element appears THREE times except for one. Find that single one.

1 class Solution { 2 public: 3 int singleNumber(int A[], int n) { 4 int bits = sizeof(int)*8; 5 int result=0; 6 for(int i=1; i<=bits; i++) 7 { 8 int w=0; 9 int t=1; 10 11 for(int j=0; j<n; j++) 12 w += (A[j]>>(i-1))&t; 13 result+= (w%3)<

[LeetCode] Range Sum Query 2D - Mutable 二维区域和检索 - 可变

Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). The above rectangle (with the red border) is defined by (row1, col1) = (2, 1) and (row2, co

3 sum allow number used multi times

class Solution { public: vector<vector<int> > ThreeSum(int a[], int n, int target) { vector<vector<int> > ret; for (int i = 0; i < n; i++) { if(i>0 && a[i] == a[i - 1]) continue; int begin = i, end = n - 1; while (beg