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 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) and (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
#include <stdio.h>
#include <stdlib.h>
int main(){
long long n, count;
double res=, tmp;
scanf("%lld", &n);
for (int i = ; i<n; i++){
count = (n - i)*(i + );
scanf("%lf", &tmp);
res += tmp*count;
}
printf("%.2lf", res); system("pause");
}
注意点:找到规律以后还要注意用long long,题目n不超过10e5,两个10e5乘起来就超过int范围了
PAT A1104 Sum of Number Segments (20 分)——数学规律,long long的更多相关文章
- 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 ...
- 【PAT甲级】1104 Sum of Number Segments (20 分)
题意:输入一个正整数N(<=1e5),接着输入N个小于等于1.0的正数,输出N个数中所有序列的和. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC ...
- PAT 甲级 1104. Sum of Number Segments (20) 【数学】
题目链接 https://www.patest.cn/contests/pat-a-practise/1104 思路 最容易想到的一个思路就是 遍历一下所有组合 加一遍 但 时间复杂度 太大 会超时 ...
- [PAT] 1144 The Missing Number(20 分)
1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...
- PAT甲级——A1104 Sum of Number Segments【20】
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- PAT甲级——A1104 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 ...
- A1104. Sum of Number Segments
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...
随机推荐
- 【Java基础】13、抽象方法不能是static或native或synchroniz 原因及误解
在网上看到过这么一篇文章,是关于抽象方法不能是static或native或synchroniz 的原因.其中提到了这些关键字的意义以及与 abstract 关键字的冲突,大体内容如下: 1.abstr ...
- Flash饼状图统计代码
index.html文件: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...
- idea vue.js插件安装
Vue.js for IntelliJ IDEA-based IDEs This plugin provides support for Vue.js in IntelliJ IDEA Ultimat ...
- 洛谷P4563 [JXOI2018]守卫(dp)
题意 题目链接 Sol 非常有意思的题目. 我们设\(f[l][r]\)表示区间\([l,r]\)的答案. 显然\(r\)位置一定有一个保镖 同时不难观察到一个性质:拿\([1, n]\)来说,设其观 ...
- centos 多个yum源,系统怎么选择
yum配置文件: /etc/yum.conf pkgpolicy:包的策略.一共有两个选项,newest和last,这个作用是如果你设置了多个repository,而同一软件在不同的repositor ...
- C# 插件式开发
在网上找了下插件式编程的资料,这里自己先借鉴下别人的,同时发现有自己的看法,不过由于本人水平有限,不一定有参考价值,写出来一方面是为了总结自己,以求提高,另一方面也希望各为朋友看到我的不足,给我提出宝 ...
- 自定义控件详解(二):Path类 相关用法
Path:路径 绘制路径:void drawPath (Path path, Paint paint) Path 可以绘制的路径 一.直线路径 1.基本方法 void moveTo (float st ...
- LaTeX:图形的填充(生成阴影图形)
将内网和外网看到的综合整理. 韦恩图Venn \documentclass{standalone} \usepackage{tikz} %导出为图片需要安装imagemagick %https://t ...
- Kotlin入门(2)让App开发变得更容易
上一篇文章介绍了如何搭建Kotlin的开发环境,可是这个开发环境依然基于Android Studio,而在Android Studio上使用Java进行编码,本来就是理所应当的,何必还要专门弄个Kot ...
- (网页)js最新手机号码、电话号码正则表达式
正则表达式(regular expression)是一个描述字符模式的对象.使用JavaScript正则表达式可以进行强大的模式匹配和文本检索与替换功能. 手机号码正则表达式验证. function ...