一個(gè)學(xué)生等老師來(lái)上課的,但是他不知道老師啥時(shí)候會(huì)來(lái)的,然后他等waiting時(shí)間后覺(jué)得無(wú)聊就會(huì)出去轉(zhuǎn)walking時(shí)間,回來(lái)等待waiting時(shí)間后老師沒(méi)來(lái)就會(huì)再次出去。老師會(huì)在a...b區(qū)間時(shí)間任意時(shí)刻來(lái),是等概率的。但是老師等t時(shí)間后,就會(huì)不會(huì)讓你進(jìn)來(lái)了的。讓你求你進(jìn)不去教室的概率是多少。(所有的數(shù)<= 1000W)
十多年建站經(jīng)驗(yàn), 網(wǎng)站設(shè)計(jì)、網(wǎng)站制作客戶的見(jiàn)證與正確選擇。成都創(chuàng)新互聯(lián)提供完善的營(yíng)銷(xiāo)型網(wǎng)頁(yè)建站明細(xì)報(bào)價(jià)表。后期開(kāi)發(fā)更加便捷高效,我們致力于追求更美、更快、更規(guī)范。思路:因?yàn)樾∮?000w,所以我就暴力把每一分鐘的狀態(tài)都統(tǒng)計(jì)出來(lái)。
注意長(zhǎng)度為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;
typedeflong 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 Code500pt:
給定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 k, n.給定k,n(k <= 50, n <= 10^9),求supersum(k,n)
思路:乍一看不會(huì)做,然后就打了個(gè)20*20的表,發(fā)現(xiàn)斜著看就是一個(gè)楊輝三角,然后直接算可以了
答案就是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
分享名稱:SRM467-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://jinyejixie.com/article12/icpgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、網(wǎng)站設(shè)計(jì)公司、關(guān)鍵詞優(yōu)化、品牌網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、小程序開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容