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. 如果要对一些数据做处理,可以直接用自定义fliter

    {{[offer.brand, offer.series, offer.model] | carFilter}} filters里面写 carFilter ([brand, series, model ...

  2. IDEA 调试图文教程,让 bug 无处藏身!

    阅读本文大概需要 6.2 分钟. 来源:http://t.cn/EoPN7J2 Debug用来追踪代码的运行流程,通常在程序运行过程中出现异常,启用Debug模式可以分析定位异常发生的位置,以及在运行 ...

  3. jvm (一)jvm结构 & 类加载 & 双亲委托模型

    参考文档: jvm内幕-java虚拟机详解:http://www.importnew.com/17770.html 常量池:https://www.jianshu.com/p/c7f47de2ee80 ...

  4. SpringAOP ApectJ 动态代理

    参考链接:https://docs.spring.io/spring/docs/4.3.13.RELEASE/spring-framework-reference/htmlsingle/#aop ht ...

  5. BERT模型

    BERT模型是什么 BERT的全称是Bidirectional Encoder Representation from Transformers,即双向Transformer的Encoder,因为de ...

  6. win10安装ubuntu双系统遇到的问题

    安装过程学习了几个博客 Ubuntu 16.04与Win10双系统双硬盘安装图解:https://www.cnblogs.com/coxiseed/p/9945202.html?tdsourcetag ...

  7. C# 序列化与反序列化之Binary与Soap无法对泛型List<T>进行序列化的解决方案

    C# 序列化与反序列化之Binary与Soap无法对泛型List<T>进行序列化的解决方案 新建Console控制台项目项目,然后添加Team和Person 这2个类,如下: Team和P ...

  8. spring容器干掉if-else

    场景说明 最近新做一个项目,需要对不同店铺的商品做不同处理.例如storeA需要进行handleA操作,storeB需要进行handleB操作,如此类推 大家很容易会想到下面的实现方法 public ...

  9. Mapbox矢量瓦片标准(mapbox vector-tile-spec)

    目录 1. 目标 2. 文件格式 2.1. 文件后缀 2.2 MIME类型 3. 投影和范围 4. 内部结构 4.1. 图层 4.2. 要素 4.3. 几何图形编码 4.4. 要素属性 4.5. 示例 ...

  10. docker部署spring boot项目在服务器上

    IDE:idea 工具:docker spring boot:2.0.1 ======================================== 简单记录一下流程,以供参考: 第一步:首先得 ...