数值计算:

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

代码:

 #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. nodejs 中koa框架下的微信公众号开发初始篇

    最近在搞微信公众号开发,后端采用的是nodejs下的koa框架,初识后端的菜鸟,自己搞难度太大了,网上找了很多文章,采用的中间件大都是express框架下的,不过好在爬了许多坑之后总算看见点曙光了,遂 ...

  2. Linux安装QQ 2017

    网上有很多wineQQ,是基于2012或者2013做的,然而当安装好后登录他会提示版本过来,我在优麒麟的应用商店里找到了一个基于国际版QQ的Wine版本,这里说下安装过程. 先上两张成果图: 下载地址 ...

  3. 借用网上大神的一些知识,html5 video 视频播放都兼容(Android,iOS,电脑)

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  4. jQuery各种选择器总结

    首先介绍几个简单的: id选择器 $('#p1').html('<font color='red'>nihao</font>); 类选择器:表示页面上所有应用了a样式的标签 $ ...

  5. Bootstarp--全局CSS样式之表格

    表格在实际开发中可以说是非常常见的,但是有很多人不喜欢使用表格,但个人觉得在简单的界面布局中使用表格还是很简单的.毕竟人家给了表格这元素,而你却不去使用,貌似有点不解风情. 下面简单介绍Bootstr ...

  6. Java对数组对象进行排序

    下面是一组对数组对象进行排序的代码: package com.sun; import java.util.ArrayList; import java.util.Arrays; import java ...

  7. 学习java随笔第五篇:流程控制

    条件语句 if(表达式){方法体}else if(表达体)else{方法体} 简写形式:if... 一般形式:if...else... 完整形式:if...else if...else 分支语句 sw ...

  8. 微信热修复tinker及tinker server快速接入

    博客: 安卓之家 掘金: jp1017 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 当前热修复方案很多,今天研究了下微信的tinker,使用效果还是不错的,配合tinker serv ...

  9. 创建Java线程池

    线程池的作用: 线程池作用就是限制系统中执行线程的数量. 根据系统的环境情况,可以自动或手动设置线程数量,达到运行的最佳效果:少了浪费了系统资源,多了造成系统拥挤效率不高.用线程池控制线程数量,其他线 ...

  10. swift 截取字符串