瀏覽單個文章
chrisdar
Power Member
 
chrisdar的大頭照
 

加入日期: Jan 2002
文章: 566
很簡單

正向推導:
隨便抓一題有可能是
甲對乙不對 7/10*3/10
甲不對乙對 3/10*7/10
甲乙都對 7/10*7/10
總和是 91/100 91%

反向推導:
甲或乙對 反向後 甲不對且乙不對 3/10*3/10 = 9%
結果是1-9% = 91%


code:

#include <iostream>
#include <algorithm>
#include <vector>
#include <time.h>
#include <windows.h>
using namespace std;

int main(int argc, char *argv[]) {
typedef std::vector<int> vector_type;
vector_type sta(10), stb(10);
for (int i = 0 ;i < 7;i++) {
sta[i] = 1;
stb[i] = 1;
}
srand(GetTickCount());
int j = 0,l=0;
for (int k = 0 ;k < 10000;k++) {
random_shuffle(sta.begin(), sta.end());
random_shuffle(stb.begin(), stb.end());
for (int i = 0 ;i < 10;i++) {
j += ((sta[i] + stb[i]) != 0);
l += ((sta[i] + stb[i]) == 0);
}
}
cout << "o : " << j / 100000.0 << endl;
cout << "x : " << l / 100000.0 << endl;
system("pause");
return 0;
}

o : 0.9085
x : 0.0915
__________________
AMD 除頻表
舊 2007-04-07, 12:24 AM #7
回應時引用此文章
chrisdar離線中