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 ...
随机推荐
- Java GC 概念摘要
很长时间,我想Java的GC做一个小小的总结,他有没有时间.根据最近看了java paper向上java gc文章,我觉得好,读读.顺便说一下,总结下. java paper的GC文章地址,里面有非常 ...
- 启动hadoop,报错Error JAVA_HOME is not set and could not be found
报如错误:JAVA_HOME is not set and could not be found,可能是因为JAVA_HOME环境没配置正确,还有一种情况是即使各结点都正确地配置了JAVA_HOME, ...
- pugixml
http://www.firedragonpzy.com.cn/index.php/archives/3227 有关cocos2d-x的xml文件读取问题
- 解决升级windows8.1 Oracle服务被刷新
1.调用CMD管理员模式,记得,否则你想要执行的东西都调用不了,win8下“窗口键+X”-“命令提示符(管理员) 2.创建oracle10g.11g的监听服务:(%ORACLE_HOME%为oracl ...
- Tcp抓包以及tcp状态解释
tcp三次握手 发送端发送一个SYN=1,ACK=0标志的数据包给接收端,请求进行连接,这是第一次握手:接收端收到请求并且允许连接的话,就会发送一个SYN=1,ACK=1标志的数据包给发送端,告诉它, ...
- 第八篇:web之前端踩的一些坑
前端踩的一些坑 前端踩的一些坑 本节内容 事件代理 清除标签的所有事件 bootstrap的模态框自定义方法 ajax在django里面实现post提交 ajax提交数据嵌套 1.事件代理 之前写 ...
- tem
有时间需要整理的东西 1.登录 2.后台框架(管理界面) 3.api详细情况调用 4.具有基础操作的模块 5.session 6.操作权限控制
- CSS伪类选择器和伪元素选择器
CSS的伪类选择器常用的是link/visited/hover/active,分别对应未访问.已访问过.鼠标悬停.鼠标按下时的样式,常用于链接,使用时要按此顺序依次写CSS,不能乱 a:link{ba ...
- Asp.Net MVC Ajax
将ASP.NET MVC中的form提交改为ajax提交 在ASP.NET MVC视图中通过 @using (Html.BeginForm()) 产生的是form表单提交代码,可以用javascrip ...
- (转)分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)
分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...