hdu 4498 自适应simpson
来源:互联网 发布:四旋翼飞控编程 编辑:程序博客网 时间:2024/06/06 07:13
传送门
题意:
给出k1,k2,…,kn, a1,a2,…,an 和 b1,b2,…,bn
求函数:
F(x)=min{100,min{ki*(x-ai)^2+bi | 0 < i <= n}}
在坐标上画出的曲线的长度。
限制:
1 <= n <= 50; 0 <= ai,bi < 100; 0 < ki < 100
思路:
先求出所有交点,然后排序,把函数分段,然后利用
L=∫[a,b] √[1+(f ‘(x))^2] dx
利用自适应simpson进行长度积分。
//china no.1#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define s_1(x) scanf("%d",&x)#define s_2(x,y) scanf("%d%d",&x,&y)#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)#define s_4(x,y,z,X) scanf("%d%d%d%d",&x,&y,&z,&X)#define S_1(x) scan_d(x)#define S_2(x,y) scan_d(x),scan_d(y)#define S_3(x,y,z) scan_d(x),scan_d(y),scan_d(z)#define PI acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define fOR(n,x,i) for(int i=n;i>=x;i--)#define fOr(n,x,i) for(int i=n;i>x;i--)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");#define db double#define ll long long#define mp make_pair#define pb push_backtypedef long long LL;typedef pair <int, int> ii;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=4e3+10;const int maxx=4e5+10;const double EPS=1e-8;const double eps=1e-8;const int mod=1e9+7;template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}template <class T>inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}void print(LL a){ Out(a),puts("");}//freopen( "in.txt" , "r" , stdin );//freopen( "data.txt" , "w" , stdout );//cerr << "run time is " << clock() << endl;int pos,n;db A[105],B[105],C[105];vector<db>Q;void cal(double a,double b,double c){//计算a*x^2+b*x+c=0的解if(a==0 && b==0)return ;if(a==0) {double t=-c/b;if(t>=0 && t<=100)Q.pb(t);return ;}double delta=b*b-4*a*c;if(delta<0) return ;if(delta==0){double t=-b/(2*a);if(t>=0 && t<=100)Q.pb(t);}else{double t1=(-b+sqrt(delta))/(2*a);double t2=(-b-sqrt(delta))/(2*a);if(t1>=0 && t1<=100)Q.pb(t1);if(t2>=0 && t2<=100)Q.pb(t2);}}int get_pos(db x){ int p=0; db minn=100; FOR(1,n,i) { db tmp=A[i]*x*x+B[i]*x+C[i]; if(tmp<minn) { minn=tmp; p=i; } } return p;}double F(double x1){ return sqrt(1.0+(x1*2*A[pos]+B[pos])*(x1*2*A[pos]+B[pos]));}double simpson(double a,double b){ double c = a + (b-a)/2; return (F(a) + 4*F(c) + F(b))*(b-a)/6;}double asr(double a,double b,double eps,double A){ double c = a + (b-a)/2; double L = simpson(a,c); double R = simpson(c,b); if(fabs(L+R-A) <= 15*eps)return L+R+(L+R-A)/15; return asr(a,c,eps/2,L) + asr(c,b,eps/2,R);}double asr(double a,double b,double eps){ return asr(a,b,eps,simpson(a,b));}int t;db a,b,k;int main(){ s_1(t); W(t--) { s_1(n); A[0]=0; B[0]=0; C[0]=100; FOR(1,n,i) { scanf("%lf%lf%lf",&k,&a,&b); A[i]=k; B[i]=-2.0*a*k; C[i]=k*a*a+b; } Q.clear(); FOr(0,n,i) { FOR(i+1,n,j) { cal(A[i]-A[j],B[i]-B[j],C[i]-C[j]); } } db ans=0; Q.pb(0); Q.pb(100); sort(Q.begin(),Q.end()); FOr(0,Q.size()-1,i) { db l=Q[i];db r=Q[i+1]; if(fabs(r-l)<eps) continue; db mid=(l+r)/2; pos=get_pos(mid); //cout<<pos<<endl; ans+=asr(l,r,eps); //printf("%f\n",ans); } printf("%.2f\n",ans); }}
阅读全文
0 0
- hdu 4498 自适应simpson
- hdu 4498 自适应simpson
- hdu 1724 自适应 simpson 算法 求积分
- hdu 1724 自适应simpson 或 romberg
- HDU 1724 Ellipse 【自适应Simpson积分】
- HDU 1724 自适应Simpson积分 解题报告
- hdu 1724 Ellipse(自适应Simpson积分) (模板)
- 【自适应Simpson积分】hdu 1724 Ellipse
- HDOJ-4498 Function Curve(自适应Simpson积分)
- HDU-#1724 Ellipse(自适应Simpson法+数值积分)
- HDU 1724 Ellipse 自适应simpson函数模板题(二)
- [自适应Simpson]Ellipse
- 【二分】【自适应Simpson】Bridge
- 自适应simpson积分
- 自适应Simpson积分
- 自适应simpson 积分
- HDU 4498 Function Curve (分段, simpson)
- Hdu 4498 Function Curve(Simpson积分)
- 简单指南针icon(不像icon的icon..)
- Qt与MSVC中文乱码问题的解决方案
- 三、JS【JavaScript弱类型的脚本语言】03
- LeetCode:Find Largest Value in Each Tree Row
- python shelve模块的用法
- hdu 4498 自适应simpson
- WebRTC视频帧渲染前处理——等比例填充显示窗口
- 滴滴出行之地下迷宫
- 移动大脑-SpringMVc搭建RestFul后台服务(一)-环境搭建
- 第四章 对象与类
- 学习记录7(17/10/02 于隆昌)
- HTML 注释 水平线
- GDB调试器&Make工程管理器
- kk《必然》后感之'知化'