Function Evaluation
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的更多相关文章
- 如何解决Visual Studio调试Debug很卡很慢
http://brightguo.com/make-debugging-faster-with-visual-studio/ Have you ever been frustrated by slow ...
- HANA SQLScript
数据类型 日期时间类型 DATE(日期) DATE 数据类型由年.月.日信息组成,表示一个日期值. DATA 类型的默认格式为‘YYYY-MM-DD’. YYYY 表示年, MM 表示月而 DD 表示 ...
- C#中的属性太邪恶了
好懒,啥都不想写了.C#的属性伤透了我的心.只能相信记忆力和想象力能让我下次翻到这篇日志时能瞬间想到我们在谈瓦特. http://stackoverflow.com/questions/1224270 ...
- Deep Learning 16:用自编码器对数据进行降维_读论文“Reducing the Dimensionality of Data with Neural Networks”的笔记
前言 论文“Reducing the Dimensionality of Data with Neural Networks”是深度学习鼻祖hinton于2006年发表于<SCIENCE > ...
- (转)The Road to TensorFlow
Stephen Smith's Blog All things Sage 300… The Road to TensorFlow – Part 7: Finally Some Code leave a ...
- Akka(17): Stream:数据流基础组件-Source,Flow,Sink简介
在大数据程序流行的今天,许多程序都面临着共同的难题:程序输入数据趋于无限大,抵达时间又不确定.一般的解决方法是采用回调函数(callback-function)来实现的,但这样的解决方案很容易造成“回 ...
- 【原创】大数据基础之Impala(2)实现细节
一 架构 Impala is a massively-parallel query execution engine, which runs on hundreds of machines in ex ...
- 多项式函数插值:全域多项式插值(一)单项式基插值、拉格朗日插值、牛顿插值 [MATLAB]
全域多项式插值指的是在整个插值区域内形成一个多项式函数作为插值函数.关于多项式插值的基本知识,见“计算基本理论”. 在单项式基插值和牛顿插值形成的表达式中,求该表达式在某一点处的值使用的Horner嵌 ...
- C++开源库集合
| Main | Site Index | Download | mimetic A free/GPL C++ MIME Library mimetic is a free/GPL Email lib ...
随机推荐
- 【题解】洛谷 P2725 邮票 Stamps
目录 题目 思路 \(Code\) 题目 P2725 邮票 Stamps 思路 \(\texttt{dp}\).\(\texttt{dp[i]}\)表示拼出邮资\(i\)最少需要几张邮票. 状态转移方 ...
- 【JZOJ5553】【20190625】谜
题目 给出一个\(2\times n\)个点的二分图的邻接矩阵\(M\) 以及\(m\)个行替换元,\(k\)个列替换元 \(q\)次询问:op u v 表示用第v个行/列替换元去替换矩阵的第u行/列 ...
- Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization
Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization 2019-10-10 10:50:19 Paper ...
- 防止同一IP多次请求攻击
防止同一IP多次请求攻击 防止入侵者,通过死循环同一时间批量向服务器请求数据,导致服务器内存开销不断膨胀,最后直接瘫痪. 一. 新增一个spring的拦截器 , 拦截所有请求 <mvc:inte ...
- C语言宏应用-------#define STR(X) #X
C语言宏应用-------#define STR(X) #X #:会把参数转换为字符串 #define STR(x) #x #define MAX 100 STR(MAX) 会被扩展成" ...
- Java实现 微信小程序 + 消息推送
实现效果: 下面要显示五个字段 接下来,参照官方文档,一步步实现: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open- ...
- awk:for循环输出文件名
简单来说,有file1.txt, file2.txt, file3.txt file1.txt如下: 1 a 4 d d g file2.txt如下: 2 b g 6 9 0 file3.txt如下: ...
- hackbar简单安装使用教程
安装hackbar: 在火狐的附加组件中搜索“hackbar”,将它添加到火狐浏览器中, 重启后Firefox后安装完成,按F9键打开我们就会看到在地址栏下面会出现一个大框框就是hackbar了 框框 ...
- 使用MAT 分析内存泄漏实战
在分析前可以阅读下这篇文章,很多内容就都知道了https://www.jianshu.com/p/738b4f3bc44b,下面我来分析上一篇文章内存泄漏的为问题 1.上一篇中已经生成了hprf的文件 ...
- Playbooks简介
Playbooks简介 关于Playbooks Playbook简单示例 基本组成 主机和用户 任务列表 Handlers: 配置更改时运行操作 执行Playbook Ansible-Pull Lin ...