51nod 1836:战忽局的手段(期望)
生活随笔
收集整理的這篇文章主要介紹了
51nod 1836:战忽局的手段(期望)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接
公式比較好推
精度好難搞啊@_@
?
下面記筆記@_@
****在CodeBlocks中,輸出double型變量要使用%f (參見http://bbs.csdn.net/topics/391938535
**** long double用%LF輸出
**** __float128 精度比 long double 高(可以在中間運算時使用,輸出時把__float128強制轉化為double然后printf
**** 注意n->∞時(這道題里是1e6),可以借助極限公式@_@(有人用cmath公式就ac了,好強啊orz)
貼兩個代碼
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef __float128 LB; //親測此處long double會wa掉一半數據 LB qpow(LB x,LL k) {LB ret=1;for(;k;k>>=1){if(k&1) ret*=x;x=x*x;}return ret; }int main() {int T;scanf("%d",&T);while(T--){LL n,m;scanf("%lld%lld",&n,&m); // cin>>n>>m;LB t=qpow((LB)(n-1)/n,m)*n;LB ans=n-t; // cout<<ans<<endl;printf("%.7lf\n",(double)ans);} }?
#include<bits/stdc++.h> int main() {int T;scanf("%d",&T);while(T--){double n,m;scanf("%lf%lf",&n,&m);if(n<1e6)printf("%f\n",n*(1-pow(1.0*(n-1)/n,m)));else printf("%f\n",n*(1-exp(-1.0*m/n)));} }?
轉載于:https://www.cnblogs.com/Just--Do--It/p/6419647.html
總結
以上是生活随笔為你收集整理的51nod 1836:战忽局的手段(期望)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java编程基础-变量
- 下一篇: 动态库和静态库的创建