PAT_B_1049 fragments and the number of columns

Title Description

Given a positive number series, which we can intercept any of several successive numbers, called clips. For example, a given number sequence {0.1, 0.2, 0.3, 0.4}, we have (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) The 10 fragments. 

Given positive integer sequence, and obtains the number of all fragments contain all. The 10 fragments of the present embodiment is the sum of 0.1 + 0.3 + 0.6 + 1.0 + 0.2 + 0.5 + 0.9 + 0.3 + 0.7 + 0.4 = 5.0. 

Input format: 
given input of the first line of a positive integer not more than N 10 ^ 5, the number indicates the number of columns in the second row of N gives a positive number not exceeding 1.0, the number of columns is the number of system, separated by a space. 

Output format: 
output the sequence numbers of all of the fragments contained in a row, two decimal place. 

Sample input: 
4 
0.1 0.2 0.3 0.4 
Output Sample: 
5.00  

AC Code

// the number of columns and fragments PAT_1049_ 

# the include <stdio.h> 
# 100010 DEFINE Max 

int main (void) 
{ 
	int N; 
	int I; 
	Double Val; // record the input data 
	double sum = 0; // final Solving and 
	
	Scanf ( "% D", & N); 
	
	// find weights 
	for (I =. 1; I <= N; I ++) 
	{ 
		Scanf ( "% LF", & Val); 
		SUM + = Val * I * (N- +. 1 I); 
	} 
	
	the printf ( "%. 2F.", SUM); 
	
	return 0; 
}

RR

Guess you like

Origin www.cnblogs.com/Robin5/p/11335049.html