fork download
  1. /*Author: Barish Namazov*/
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. /*TEMPLATE*/
  6. #define INF 1000000010
  7. #define intt long long
  8. #define forn(i,a,b) for(intt i=a;i<=b;i++)
  9. #define rofn(i,a,b) for(intt i=a;i>=b;i--)
  10. #define fi first
  11. #define se second
  12. #define pb push_back
  13. #define mp make_pair
  14. #define VI vector<intt>
  15. #define PII pair<intt,intt>
  16. #define VPII vector< PII >
  17. #define sqr(n) n*n
  18. #define IO ios_base::sync_with_stdio(false);cin.tie();
  19. intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
  20. intt gcd(intt a,intt b){if(!b)return a;return (b,a%b);}
  21. intt lcm(intt a,intt b){return a*b/gcd(a,b);}
  22. intt is_prime(intt n){if(n==2)return 1;forn(i,2,n)if(!n%i)return 0;return 1;}
  23. /*ENDS HERE*/
  24.  
  25. int main () {
  26. IO;
  27. intt T;
  28. scanf("%lld", &T);
  29. for (int i = 1; i <= T; i++) {
  30. intt n;
  31. double ans = 0, elem, comb = 0;
  32. scanf("%lld", &n);
  33. for (int j = 0; j <n; j++) {
  34. scanf("%lf", &elem);
  35. double tmp = log2(fabs(elem));
  36.  
  37. if (j!=0) {
  38. comb += log2(double(n-j)/j);
  39. tmp += comb;
  40. }
  41.  
  42. if (elem>=0)
  43. ans += pow(2, tmp - n + 1);
  44. else
  45. ans -= pow(2, tmp - n + 1);
  46. }
  47.  
  48. printf("Case #%d: %.3lf\n", i, ans);
  49. }
  50. return 0;
  51. }
Success #stdin #stdout 0s 3472KB
stdin
4
1
10.4
2
1.0 2.2
3
1 2 3
5
1 2 3 4 5
stdout
Case #1: 10.400
Case #2: 1.600
Case #3: 2.000
Case #4: 3.000