hdu 5065 數學題,hdu5065
#include<iostream>#include<cmath>#include<cstdio>using namespace std;int A,B,y;double ans=0;double inline f(double x){ return A*x*x-(B*sin(x)+y);}double inline absf(double x){ if(f(x)<0)return -f(x); return f(x);}bool findans(double l,double r) //求絕對值後函數必然先減後增。三分{ if(f(l)*f(r)>0)return 0; while(r-l>0.00000001) //注意精度 { double mid1=l+(r-l)/3,mid2=r-(r-l)/3; if(absf(mid1)<=absf(mid2)) r=mid2; else l=mid1; } ans=l; return 1;}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d%d%d",&A,&B,&y); bool marks=0;ans=0; for(double x=0;x<50;x=x+0.3) { if(findans(x,x+0.3)) { marks=1;break; } } if(marks) printf("%.5lf\n",ans); else printf("error\n"); } return 0;}
hdu4159,很水很水的一道數學機率題,誰幫忙看下
若n(排隊的人)>s(Indomie) 100%
s==0, 0%
其他情況,設Ai為i個人選Indomie的事件總數
那麼 Ai=C(n,i) /*n個人i各選Indomie*/ * 2^(n-i) /* 其餘人可能選rice 或者 sugar */
還有Indomie剩下的機率為 ΣAi(i=0,1,2,…s-1) / ΣAi(i=0,1,2,…, s);
HDU 1071簡單的數學用積分面積我下面的程式什地方有問題指教或者還有什更好的方法?
按acm.hdu.edu.cn/showproblem.php?pid=1071的要求,是求陰影的面積
拿你的程式運行一下:
1
5 5 0 0 10 0
33.33 <======正確
再次運行
1
5 10 0 5 10 5
83.33 <======錯誤
第二次的P1 P2 P3三點是把第一次的三點上移5個單位,各點相對位置不變,面積也不會變
83.33-53.33=50= 5X10 ,就是說你把空白面積加進來了,
解決辦法:減去P2P3和x軸之間的梯形面積