zoukankan      html  css  js  c++  java
  • SRM467

    250pt:

         一个学生等老师来上课的,但是他不知道老师啥时候会来的,然后他等waiting时间后觉得无聊就会出去转walking时间,回来等待waiting时间后老师没来就会再次出去。老师会在a...b区间时间任意时刻来,是等概率的。但是老师等t时间后,就会不会让你进来了的。让你求你进不去教室的概率是多少。(所有的数<= 1000W)

    思路:因为小于1000w,所以我就暴力把每一分钟的状态都统计出来。

          注意长度为0的情况即可(比如老师即到即走的情况)举要特判

    #line 7 "LateProfessor.cpp"
    #include <cstdlib>
    #include <cctype>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <iostream>
    #include <sstream>
    #include <map>
    #include <set>
    #include <queue>
    #include <stack>
    #include <fstream>
    #include <numeric>
    #include <iomanip>
    #include <bitset>
    #include <list>
    #include <stdexcept>
    #include <functional>
    #include <utility>
    #include <ctime>
    using namespace std;
    
    #define PB push_back
    #define MP make_pair
    
    #define REP(i,n) for(i=0;i<(n);++i)
    #define FOR(i,l,h) for(i=(l);i<=(h);++i)
    #define FORD(i,h,l) for(i=(h);i>=(l);--i)
    
    typedef vector<int> VI;
    typedef vector<string> VS;
    typedef vector<double> VD;
    typedef long long LL;
    typedef pair<int,int> PII;
    
    
    class LateProfessor
    {
            public:
            double getProbability(int wait, int walk, int late, int st, int end)
            {
                  double sum = (end - st);
                  int m = wait + walk;
                  double ans = 0;
                //  int last = -1, len = 0;
                  if (st == end){
                        if (st % m <= wait || (st % m > wait && st % m + late > m)) return 0.0;
                        return 1.0;       
                  }
                  for (int i = st; i < end; ++i){
                        if (i % m < wait || (i % m >= wait && i % m + late >= m)) ++ans;
                  }
                  return 1 - ans / sum;
            }
    
    };
    View Code

    500pt:

    给定supersum定义如下

    • SuperSum(0 , n) = n, for all positive n.
    • SuperSum(k , n) = SuperSum(k-1 , 1) + SuperSum(k-1 , 2) + ... + SuperSum(k-1 , n), for all positive kn.

    给定k,n(k <= 50, n <= 10^9),求supersum(k,n)

    思路:乍一看不会做,然后就打了个20*20的表,发现斜着看就是一个杨辉三角,然后直接算可以了

             答案就是C(n + k, k + 1)

     1 #line 7 "SuperSum.cpp"
     2 #include <cstdlib>
     3 #include <cctype>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <algorithm>
     8 #include <vector>
     9 #include <string>
    10 #include <iostream>
    11 #include <sstream>
    12 #include <map>
    13 #include <set>
    14 #include <queue>
    15 #include <stack>
    16 #include <fstream>
    17 #include <numeric>
    18 #include <iomanip>
    19 #include <bitset>
    20 #include <list>
    21 #include <stdexcept>
    22 #include <functional>
    23 #include <utility>
    24 #include <ctime>
    25 using namespace std;
    26 
    27 #define PB push_back
    28 #define MP make_pair
    29 
    30 #define REP(i,n) for(i=0;i<(n);++i)
    31 #define FOR(i,l,h) for(i=(l);i<=(h);++i)
    32 #define FORD(i,h,l) for(i=(h);i>=(l);--i)
    33 #define M 1000000007
    34 typedef vector<int> VI;
    35 typedef vector<string> VS;
    36 typedef vector<double> VD;
    37 typedef long long LL;
    38 typedef pair<int,int> PII;
    39 
    40 class SuperSum
    41 {
    42         public:
    43         long long power(long long a, long long b){
    44              long long ret = 1;
    45              while (b){
    46                  if (b&1) ret = (ret * a) % M;
    47                  b >>= 1;
    48                  a = (a * a) % M;
    49              }
    50              return ret;
    51         }
    52         long long C(int n, int m){
    53              long long ret = 1;
    54              for (int i = 1; i <= m; ++i){
    55                  ret = (ret * power(i, M - 2)) % M;
    56                  ret = (ret * (n - i + 1)) % M;
    57              }
    58              return ret;
    59         }
    60         int calculate(int K, int N)
    61         {
    62                 int n = K + N;
    63                 int m = K + 1;
    64                 return C(n, m);
    65         }
    66 
    67 };
    View Code
  • 相关阅读:
    sqlserver计算时间差DATEDIFF 函数
    C# join 子句(C# 参考)
    C# join 子句(C# 参考)
    MongoDB 监控备份工具MMS
    MongoDB 监控备份工具MMS
    mongodb$slice (aggregation)
    mongodb$slice (aggregation)
    1004:字符三角形
    1004:字符三角形
    1003:对齐输出
  • 原文地址:https://www.cnblogs.com/yzcstc/p/3602539.html
Copyright © 2011-2022 走看看