HDU 4498 Function Curve (自适应simpson)
Function Curve
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 203 Accepted Submission(s): 67
Then we draw F(x) on a xy-plane, the value of x is in the range of [0,100]. Of course, we can get a curve from that plane.
Can you calculate the length of this curve?
Then T blocks follow, which describe different test cases.
The first line of a block contains an integer n ( 1 <= n <= 50 ).
Then followed by n lines, each line contains three integers ki, ai, bi ( 0<=ai, bi<100, 0<ki<100 ) .
3
1 2 3
4 5 6
7 8 9
1
4 5 6
278.91
All test cases are generated randomly.
数值方法计算积分
/* ***********************************************
Author :kuangbin
Created Time :2013-10-9 12:04:07
File Name :E:\2013ACM\专题学习\数学\积分\HDU4498.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; vector<double>x; void add(int a1,int b1,int c1)//计算a1*x^2 + b1*x + c = 0的解
{
if(a1 == && b1 == )
{
return;
}
if(a1 == )
{
double t = -c1*1.0/b1;
if(t >= && t <= )
x.push_back(t);
return;
}
long long deta = b1*b1 - 4LL*a1*c1;
if(deta < )return;
if(deta == )
{
double t = (-1.0 * b1)/(2.0 * a1);
if(t >= && t <= )
x.push_back(t);
}
else
{
double t1 = (-1.0 * b1 + sqrt(1.0*deta))/(2.0*a1);
double t2 = (-1.0 * b1 - sqrt(1.0*deta))/(2.0*a1);
if(t1 >= && t1 <= )
x.push_back(t1);
if(t2 >= && t2 <= )
x.push_back(t2);
}
}
int A[],B[],C[];
int best;
double F(double x1)
{
return sqrt(1.0 + (x1**A[best] + 1.0 * B[best])*(x1**A[best] + 1.0 * B[best]));
}
double simpson(double a,double b)
{
double c = a + (b-a)/;
return (F(a) + *F(c) + F(b))*(b-a)/;
}
double asr(double a,double b,double eps,double A)
{
double c = a + (b-a)/;
double L = simpson(a,c);
double R = simpson(c,b);
if(fabs(L+R-A) <= *eps)return L+R+(L+R-A)/;
return asr(a,c,eps/,L) + asr(c,b,eps/,R);
}
double asr(double a,double b,double eps)
{
return asr(a,b,eps,simpson(a,b));
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int k,a,b;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
A[] = ;
B[] = ;
C[] = ;
for(int i = ;i <= n;i++)
{
scanf("%d%d%d",&k,&a,&b);
A[i] = k;
B[i] = -*a*k;
C[i] = k*a*a + b;
}
x.clear();
for(int i = ;i <= n;i++)
for(int j = i+;j <= n;j++)
add(A[i]-A[j],B[i] - B[j],C[i] - C[j]);
double ans = ;
x.push_back();
x.push_back();
sort(x.begin(),x.end());
int sz = x.size();
for(int i = ;i < sz-;i++)
{
double x1 = x[i];
double x2 = x[i+];
if(fabs(x2-x1) < 1e-)continue;
double mid = (x1 + x2)/;
best = ;
for(int j = ;j <= n;j++)
{
double tmp1 = mid*mid*A[best] + mid*B[best] + C[best];
double tmp2 = mid*mid*A[j] + mid*B[j] + C[j];
if(tmp2 < tmp1)best = j;
}
ans += asr(x1,x2,1e-);
}
printf("%.2lf\n",ans);
}
return ;
}
HDU 4498 Function Curve (自适应simpson)的更多相关文章
- HDU 4498 Function Curve (分段,算曲线积分)
Function Curve Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)To ...
- HDU 4498 Function Curve (分段, simpson)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 最近太逗了...感觉成都要打铁了...只能给队友端 ...
- HDU 1724 Ellipse 【自适应Simpson积分】
Ellipse Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- 【BZOJ-1502】月下柠檬树 计算几何 + 自适应Simpson积分
1502: [NOI2005]月下柠檬树 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1017 Solved: 562[Submit][Status] ...
- 自适应Simpson积分
自适应Simpson积分 作用 如标题所示,这玩意就是当你不会微积分的时候来求积分的. 总所周知,积分的定义就是函数的某一段与坐标轴之间的面积. 那么,自适应Simpson积分就是一种可以再某些精度下 ...
- HDU 5608 function [杜教筛]
HDU 5608 function 题意:数论函数满足\(N^2-3N+2=\sum_{d|N} f(d)\),求前缀和 裸题-连卷上\(1\)都告诉你了 预处理\(S(n)\)的话反演一下用枚举倍数 ...
- 自适应Simpson法与积分初步
前言 不知道为什么,今天感觉想要写一下数学的东西,然后就看了一下我还有这个模板不会,顺手写了一下. 没有学过微积分的最好还是看一下求导为好. 求导 听说很多人都不会求导,我写一下吧qwq 令\(f(x ...
- HDU 5608 - function
HDU 5608 - function 套路题 图片来自: https://blog.csdn.net/V5ZSQ/article/details/52116285 杜教筛思想,根号递归下去. 先搞出 ...
- 【bzoj1502】[NOI2005]月下柠檬树 自适应Simpson积分
题目描述 李哲非常非常喜欢柠檬树,特别是在静静的夜晚,当天空中有一弯明月温柔地照亮地面上的景物时,他必会悠闲地坐在他亲手植下的那棵柠檬树旁,独自思索着人生的哲理.李哲是一个喜爱思考的孩子,当他看到在月 ...
随机推荐
- c++刷题(39/100)笔试题3
题目1: 现在你需要用一台奇怪的打字机书写一封书信.信的每行只能容纳宽度为100的字符,也就是说如果写下某个字符会导致行宽超过100,那么就要另起一行书写 信的内容由a-z的26个小写字母构成,而每个 ...
- ifconfig,netstat command not found
当CentOS7进行最小化安装时,有很多工具包是没有的. [root@vultr ~]# ifconfig -bash: ifconfig: command not found [root@vultr ...
- 在vue-cli下读取模拟数据请求服务器
写此记录时vue脚手架的webpack是3.6.0 此文章方法亦可用于vue-cli3,直接在vue.config.js里面添加 本记录使用vue-resource,先安装: cnpm install ...
- 【Python】Flask系列-模板笔记
Jinja2模板 Jinja2模板传参 如何渲染模板: 模板放在templates文件夹下 从flask中导入render_template函数. 在视图函数中,使用render_template函数 ...
- 数据库SQL中case when函数的用法
Case具有两种格式,简单Case函数和Case搜索函数.这两种方式,可以实现相同的功能.简单Case函数的写法相对比较简洁,但是和Case搜索函数相比,功能方面会有些限制,比如写判断式. 简单Cas ...
- Python黑魔法
1. 赋值 In [1]: x = 1 ...: y = 21 ...: print x, y ...: ...: x, y = y, x ...: print x, y 1 21 21 1 2. 列 ...
- 启动tomcat的时候爆出如下错误
The JRE_HOME environment variable is not defined correctly This environment 解决办法: https://blog.csdn. ...
- spring-mvc集成 swagger
问题1:spring-mvc集成 swagger, 配置好后界面 404, 原因: dispatcher-servlet.xml 文件中, 要在这上面 <!-- 启用spring mvc 注解 ...
- 学会用各种姿势备份MySQL数据库
学会用各种姿势备份MySQL数据库 前言 为什么需要备份数据? 数据的备份类型 MySQL备份数据的方式 备份需要考虑的问题 设计合适的备份策略 实战演练 使用cp进行备份 使用mysqldump+复 ...
- bootstrap fileinput插件使用感悟
bootstrap fileinput 的填坑感悟 这个插件在demo的网站地址http://plugins.krajee.com/file-preview-icons-de ...