German Collegiate Programming Contest 2013:E
数值计算:
这种积分的计算方法很好,学习一下!
代码:
#include <iostream>
#include <cmath>
using namespace std;
const double eps = 10e-; double func(double a, double b, double x)
{
double r = a * exp(- x*x) + b * sqrt(x);
return r*r;
} double integrate(double a, double b, double h)
{
unsigned long steps = , it = ;
double V = h*(func(a,b,)+func(a,b,h))/2.0;
double Vold;
do
{
double tmp = ;
steps *= ;
for (unsigned long i = ; i < steps; i += )
{
tmp += func(a, b, (h * i) / steps);
}
Vold = V;
V = (V / 2.0) + ((tmp * h) / steps);
}
while (fabs(V - Vold) > eps);
return V;
} int main()
{
double V, a, b, h;
double e_min = 2e100;
int i_min = ;
int N;
cin >> V >> N;
V /= 3.14159265358979;
for (int i = ; i < N; i++)
{
cin >> a >> b >> h;
double e = fabs(V -integrate(a, b, h));
if (e < e_min)
{
e_min = e;
i_min = i;
}
}
cout << i_min << endl;
return ;
}
German Collegiate Programming Contest 2013:E的更多相关文章
- German Collegiate Programming Contest 2013:B
一个离散化的简单题: 我用的是STL来做的离散化: 好久没写离散化了,纪念一下! 代码: #include<cstdio> #include<cstring> #include ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem A
Problem A Almost Palindrome Given a line of text, find the longest almost-palindrome substring. A st ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem F
Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem H
Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem I
Problem I Interesting Calculator There is an interesting calculator. It has 3 rows of button. Row 1: ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem J
Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem G
Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student n ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem L
Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem C
Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...
随机推荐
- Activity中的四种启动模式
在Android中每个界面都是一个Activity,切换界面操作其实是多个不同Activity之间的实例化操作.在Android中Activity的启动模式决定了Activity的启动运行方式. An ...
- the Linux Kernel: Traffic Control, Shaping and QoS
−Table of Contents Journey to the Center of the Linux Kernel: Traffic Control, Shaping and QoS 1 Int ...
- Myapplication的作用与理解
1.前沿在设置里面,对应于某一个应用,虽然没有启动,但是上面有一个终止按钮,说明这个应用时启动的,只是里面没有Activity,所以说使用android退出把一个应用退出,实际上他所对应的Applic ...
- myeclipse自动生成可持久化类的映射文件的方法
1.打开DB Browser,新建一个数据库的连接,找到想要持久化操作的数据库表的图标,右键选择hibernate reverse engineering 2.之后出现如下所示: java src f ...
- Android 开发之自定义Dialog及UI的实现
我们在开发中,经常会自定义Dialog,因为原生的AlertDialog无法满足我们的需求,这个时候就需要自定义Dialog,那么如何自定义呢,其实不难,就是有点繁琐而已.也就是自定义一个UI的xml ...
- Actioncontext跟ServletActionContext的区别---未完待续
//public class BaseAction extends ActionSupport{ public static HttpServletRequest getRequest(){ retu ...
- 自己写的SqlHelper
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- oracle编译 失效对象方式
如果procedure 所使用的表结构发生了改变等其它情况,在相应的xxx_objects表的status字段会变为invalid状态,但是如果在调用时procedure会自动编译,grant失效对象 ...
- Net的struct的内存对齐问题
很少有人谈起struct的内存对齐问题, 就是在很多C#书中, 也很少提及. 但在实际应用中, 如果不注意内存对齐, struct比较大的话, 则会浪费一定的内存. 先从一个实例看起. publ ...
- [转]看看国外的javascript题目,你能全部做对吗?
叶小钗 的博客最近都在讨论面试题目 正好以前也看过一篇,就借花献佛拿出来分享一下 http://perfectionkills.com/javascript-quiz/ 附带了自己的理解,答案有争议的 ...