标签:ace 超时 double algorithm printf segment cti pre lan
寻找规律,找到每个位置中的数出现的总次数,不然会超时
sum += t*(i+1)*(n-i);
sum += (i+1)*(n-i)*t;
把double放在后面最后两个测试点就过不去#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
// 18:42 - 19:31
using namespace std;
int n;
int main(){
scanf("%d", &n);
double sum = 0;
for(int i=0;i<n;i++){
double t;
scanf("%lf", &t);
printf("%d - %f %f\n", i, (i+1)*(n-i)*t, t*(i+1)*(n-i));
sum += t*(i+1)*(n-i);
}
printf("%.2f", sum);
}
1104 Sum of Number Segments (20分)
标签:ace 超时 double algorithm printf segment cti pre lan
原文地址:https://www.cnblogs.com/d-i-p/p/12458056.html