数值计算:

这种积分的计算方法很好,学习一下!

代码:

 #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的更多相关文章

  1. German Collegiate Programming Contest 2013:B

    一个离散化的简单题: 我用的是STL来做的离散化: 好久没写离散化了,纪念一下! 代码: #include<cstdio> #include<cstring> #include ...

  2. 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 ...

  3. 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 ...

  4. 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. ...

  5. 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: ...

  6. 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, ...

  7. 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 ...

  8. 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 ...

  9. The Ninth Hunan Collegiate Programming Contest (2013) Problem C

    Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...

随机推荐

  1. mysql加入�管理员

    1.首先用超级管理员登录,然后点击权限button 2.点击加入�新用户,填写登录名和password,全局权限不用选,点击新建用户button 3.编辑新加入�的用户(编辑权限) 4.找到" ...

  2. android 双卡手机发短信/判断手机是否为双卡

    通过反射发现sendMultipartTextMessage多了一个phoneType的参数,这个参数就是这只用GMS还是CDMA卡发送的. phoneType获取方法,iTelephony.getA ...

  3. 深度剖析:CDN内容分发网络技术原理--转载

    1.前言 Internet的高速发展,给人们的工作和生活带来了极大的便利,对Internet的服务品质和访问速度要求越来越高,虽然带宽不断增加,用户数量也在不断增加,受Web服务器的负荷和传输距离等因 ...

  4. 装有Win7系统的电脑在局域网不能共享的解决方案

    Win7系统的网络功能比XP有了进一步的增强,使用起来也相对清晰.但是由于做了很多表面优化的工作,使得底层的网络设置对于习惯了XP系统的人来说变得很不适应,其中局域网组建就是一个很大的问题.默认安装系 ...

  5. 必应代码搜索 Bing Code Search 安装

    微软这几天推出基于bing搜索引擎的  Bing Code Search ,可直接在浏览器上搜索和运行代码.目前中文版必应无法使用本功能,有需要的同学可以转到英文版进行搜索: 英文版必应:  http ...

  6. linux下安装memcached过程

    前一次已经安装过memcached,没有做记录,太久没有操作了也没有记录有点生疏,做一下笔记,已背后用. 下载文件                            下载memcached服务端, ...

  7. Android多屏幕适配

    转载:http://mikewang.blog.51cto.com/3826268/865304 问题: 测试时,发现应用在不同的显示器上显示效果不同(部分文本不能显示完全),自然想到屏幕适配的问题. ...

  8. thinkphp3.2.x版本中图片上传缩略图的解决方案

    调用方式很简单 get_sc($cover_id,[$width=180,$height=auto,$cut]) @param $cover_id 图片ID___ @param $width 宽度__ ...

  9. Bootstrap后台使用问题汇总(一)

    第一次自己汇总写博客啊,不懂规矩,大家包涵~~ 最近进行的项目中需要一个后台,于是在网上Down了许多Bootstrap后台源码.精挑细选决定用“ACE后台管理系统”(因为是中文的,英文三级狗的小鹿还 ...

  10. Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合

    项目环境背景: 操作系统:win7 JDK:1.7 相关依赖包,截图如下: