Author: Leisureeen

Time Limit: 100ms

Memory Limit: 65535KB

Code Size Limit: 16 KB

64-bit integer IO format: %lld


Here given a function, you are supposed to calculate the function value.

Input Specification:

Each input file contains one test case. For each test case, the first line gives only one positive integer x (1 <= x <= 5).

Output Specification:

For each test case you should output the function value in one line. Notice that there must be NO extra space at the end of the line. Please be accurate to x decimal place.

Sample Input:

1

Sample Output:

0.9


本人针对此题给出2种思路,首先我们可以将sinx展开,逐项积分,得到结果如下图。

然后编程实现即可,注意这里不要加到无穷,精确到题目要求后几位就行了,代码如下。

 #include<stdio.h>

 int main(void)
{
int x=,n=;
for(x=;x<=;x++)
{
double m=0.0,s=0.0;
for(n=,m=x;m/n>1e-;n+=)
{
if(n-&)
s-=m/n;
else
s+=m/n;
m*=x*x;
m/=n+;
m/=n+;
}
printf("%.8lf\n",s);
}
return ;
}

运行结果如下。

0.94608307
1.60541298
1.84865253
1.75820313
1.54993124
1.42468755
1.45459661
1.57418682
1.66504008
1.65834760

然后本题还可以利用定积分的定义(被积函数在x=0处无定义,但极限值为1)来做,无限(实际上是分得很小)分割对小矩形面积求和,代码如下。

 #include<stdio.h>
#include<math.h>
#define M 8000000.0 int main(void)
{
int x=;
for(x=;x<=;x++)
{
double m=0.0,s=1.0;
for(m=/M;m<(double)x;m+=/M)
s+=sin(m)/m;
printf("%.8lf\n",s/M);
}
return ;
}

运行结果如下。

0.94608308
1.60541307
1.84865259
1.75820321
1.54993130
1.42468761
1.45459668
1.57418689
1.66504014
1.65834765

最后针对本题,可以写出解题代码如下。

 #include<stdio.h>

 int main(void)
{
int x=;
char *key[]={"0.9","1.61","1.849","1.7582","1.54993"};
scanf("%d",&x);
printf("%s",key[x-]);
return ;
}

Function Evaluation的更多相关文章

  1. 如何解决Visual Studio调试Debug很卡很慢

    http://brightguo.com/make-debugging-faster-with-visual-studio/ Have you ever been frustrated by slow ...

  2. HANA SQLScript

    数据类型 日期时间类型 DATE(日期) DATE 数据类型由年.月.日信息组成,表示一个日期值. DATA 类型的默认格式为‘YYYY-MM-DD’. YYYY 表示年, MM 表示月而 DD 表示 ...

  3. C#中的属性太邪恶了

    好懒,啥都不想写了.C#的属性伤透了我的心.只能相信记忆力和想象力能让我下次翻到这篇日志时能瞬间想到我们在谈瓦特. http://stackoverflow.com/questions/1224270 ...

  4. Deep Learning 16:用自编码器对数据进行降维_读论文“Reducing the Dimensionality of Data with Neural Networks”的笔记

    前言 论文“Reducing the Dimensionality of Data with Neural Networks”是深度学习鼻祖hinton于2006年发表于<SCIENCE > ...

  5. (转)The Road to TensorFlow

    Stephen Smith's Blog All things Sage 300… The Road to TensorFlow – Part 7: Finally Some Code leave a ...

  6. Akka(17): Stream:数据流基础组件-Source,Flow,Sink简介

    在大数据程序流行的今天,许多程序都面临着共同的难题:程序输入数据趋于无限大,抵达时间又不确定.一般的解决方法是采用回调函数(callback-function)来实现的,但这样的解决方案很容易造成“回 ...

  7. 【原创】大数据基础之Impala(2)实现细节

    一 架构 Impala is a massively-parallel query execution engine, which runs on hundreds of machines in ex ...

  8. 多项式函数插值:全域多项式插值(一)单项式基插值、拉格朗日插值、牛顿插值 [MATLAB]

    全域多项式插值指的是在整个插值区域内形成一个多项式函数作为插值函数.关于多项式插值的基本知识,见“计算基本理论”. 在单项式基插值和牛顿插值形成的表达式中,求该表达式在某一点处的值使用的Horner嵌 ...

  9. C++开源库集合

    | Main | Site Index | Download | mimetic A free/GPL C++ MIME Library mimetic is a free/GPL Email lib ...

随机推荐

  1. minikube 安装试用

    目前使用k8s 要么用的物理机搭建的环境,要么就是使用docker for mac 中kubernetes 的特性,为了本地调试方便,使用下minikube minukube 包含的特性 负载均衡器 ...

  2. go中的字符串数值转化

    #string到int int,err := strconv.Atoi(string) #string到int64 int64, err := strconv.ParseInt(string, 10, ...

  3. [Android] Android studio gradle 插件的版本号和 gradle 的版本号 的对应关系

    [Android] Android studio gradle 插件的版本号和 gradle 的版本号 的对应关系 本博客地址: wukong1688 本文原文地址:https://www.cnblo ...

  4. 【转】Spring线程及线程池的使用

    spring @Async 线程池使用 最近公司项目正逐渐从dubbo向springCloud转型,在本次新开发的需求中,全部使用springcloud进行,在使用时线程池,考虑使用spring封装的 ...

  5. spring mvc中添加对Thymeleaf的支持

    一.下载Thymeleaf 官方下载地址:https://dl.bintray.com/thymeleaf/downloads/thymeleaf/ 我下载的是最新的3.0.11版本 把包里的jar包 ...

  6. t5_sumdoc.txt

    C:\Users\Administrator\Documents\sumdoc 2019\sumdoc t5 final\sumdoc t511C:\Users\Administrator\Docum ...

  7. Mysql 有数据更新,无则插入

    项目中需要去更新数据的版本号. INSERT INTO Biz_CourseErrorBookDetail (CourseID,QuestionID,StudentID,ErrorCount,Last ...

  8. wms证书配置操作

      1. 在应用的/home下 把证书cp到/usr/local/apache2/conf 2. 打开文件/usr/local/apache2/conf/extra/httpd-ssl.conf,找到 ...

  9. 转 linux 添加PHP环境变量,/etc/profile 不生效,每次都要 source /etc/profile

    http://shanhuxueyuan.com/news/detail/46.html 执行php -v 提示未找到命令,这是因为没有将php路径添加到环境变量 方法一:直接运行命令export P ...

  10. Linux 修改用户的JDK版本

    1.  vi .bash_profile 2.复制以下到bash_profile 文件,并将此文件里原来的JAVA_HOME和PATH删掉 JAVA_HOME=/java/jdk1..0_22 JRE ...