csu_1179sum 수학 계산

1179: Sum


Time Limit: 10 Sec
Memory Limit: 128 MB
SUBMIT: 773
Solved: 118
[SUBMIT] [STATUS]

Description


Here is an easy problem.It is so easy that you just need to solve a sum:
∑min(k,max(0,x-k)).The index k is an integer,sum from 0 to +inf.
Give you real x,you should evaluate the sum.

Input


There are sevral test cases.One line for each case containing 1 real x,0<=x<1000000.00.

Output


There should be one output line per test case containing the value of the sum,correct to two decimal places.

Sample Input

0
1
2
4.6

Sample Output

0.00
0.00
1.00
5.20

HINT


직접 누가하여 화해를 구했다
#include<stdio.h>

double solve(double x)
{
    double k,n,n2,m;
    // 。。。
    n=double(int(x));
    n2=double(int(x/2));
    m=n-n2;
    double sum;
    sum=(1+n2)*n2*1.0/2.0-(n2+1 +n)*m*1.0/2.0+m*x;
    return sum;
}
int main()
{
    double x;
    while(scanf("%lf",&x)==1)
        printf("%.2lf
",solve(x)); return 0; }

남의 큰 소의 표칭을 보고 마음이 순식간에 굴러갔다
/*
A:k x-k k, k x/2 k x-k ,
 x-k, 1~n x-k 1~n k
 , n x-n,  (x - n) * n
*/
// :NARUTO
// :CSGrandeur
//2012.03.05
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
	double x;
	int n;
	while(scanf("%lf", &x) != EOF)
	{
		n = (int)(x + 1) >> 1;
		printf("%.2f
", (x - n) * n); } return 0; }

좋은 웹페이지 즐겨찾기