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. Sublime Text 3安装Package Control并安装Processing插件

    由于PDE编辑界面对中文的支撑太差,于是想换到ST3来编辑代码,结果导致了噩梦的开始. 首先,找不到“Package Control”!!! 这还怎么玩~ 于是打开http://packagecont ...

  2. 菜鸟网络Java面试-社招-一面(2019/11)

    个人情况 2017年毕业,普通本科,计算机科学与技术专业,毕业后在一个二三线小城市从事Java开发,2年Java开发经验.做过分布式开发,没有高并发的处理经验,平时做To G的项目居多.写下面经是希望 ...

  3. module 'torch' has no attribute 'gesv'

    新版torch不支持gesv,使用solve函数. Kt, _ = torch.gesv(P.mm(H.t()).t(), S) 改成 Kt, _ = torch.solve(P.mm(H.t()). ...

  4. dplyr

    The d is for dataframes, the plyr is to evoke pliers. Pronounce however you like. dplyr包可用于处理 R 内部或者 ...

  5. Xor-matic Number of the Graph-CodeForces - 724G

    Xor-matic Number of the Graph-CodeForces - 724G 线性基棒题 建议做这题前先看看线性基的概念,然后A掉这道题--->路径最大异或和 这两个题都用到了 ...

  6. Centos7 Nginx安装使用

    一.Nginx简介 1.什么是nginx Nginx是一款使用C语言开发的高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师Igor Sysoev ...

  7. fiddler自动生成jmeter测试脚本

    概述 昨天我们在课堂上讲了如何通过fiddler抓包,单一接口可以复制到jmeter中进行接口测试,那么如果抓包获取了大量的接口,我们如何快速实现接口转换成jmx文件呢? 今天给大家介绍fiddler ...

  8. hotspot的内存

    java memory主要分heap memory 和 non-heap memory,其计算公式如下: Max memory = [-Xmx] + [-XX:MaxPermSize] + numbe ...

  9. IntelliJ IDEA 2019从入门到癫狂 图文教程!

    阅读本文大概需要 6 分钟. 作者:yizhiwazi 来源:www.jianshu.com/p/9c65b7613c30 前言:IntelliJ IDEA 如果说IntelliJ IDEA是一款现代 ...

  10. 系统性能工具篇(sar)

    转自:系统性能工具篇(sar) 1. 介绍 内容很多 是sysstat软件包的一部分 自动运行:/etc/crontab/sysstat $ cat /etc/cron.d/sysstat # The ...