# csu_1179 sum 数学 计算

347人阅读 评论(0)

## 1179: Sum

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

## 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\n",solve(x));
return 0;
}


/*
A：k比x-k小的时候加的是k，当k比x/2大的时候k比x-k大，

*/
//题目：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\n", (x - n) * n);
}
return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：330830次
• 积分：6271
• 等级：
• 排名：第3919名
• 原创：308篇
• 转载：24篇
• 译文：0篇
• 评论：46条
我的微博
最新评论