题目大意
在不存在的 noip day3 里,小w 见到了一堆堆的谜题。
比如这题为什么会叫共轭?
他并不知道答案。
有 n 堆谜题,每堆有 ai 个,小 w 每次从剩下的谜题中选择一个,然后把所在的那一堆谜题全部丢掉。
小 w 期望多少次后丢掉第一堆?
题目分析
题目略毒。
先写出期望的计算式:
然后可以用$O(n^3)$的暴力或$O(n^2)$的动规解决(似乎?)。
有没有更快的方法?
我们举个$n=3$的栗子。
我们将$sum$使用$a_1+a_2+a_3$代替得到:
然后使用mathematica暴力化简得到:

观察一下,发现第二个式子非常优美,可以通过$O(n)$得出答案,因此我们根据这个化简式大胆假设答案:
验证一下发现好像是对的。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std; inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num; } int n; double a1; int main() { n=Get_Int(); a1=Get_Int(); double ans=n; for(int i=2; i<=n; i++) { double x=Get_Int(); ans=(ans-a1/(a1+x)); } printf("%0.8lf\n",ans); return 0; }
|