給定一個int n(3<=n<=10000),代表n邊形和n只螞蟻,請返回一個double,爲相撞的概率。
分析:總共有2^n可能,不相碰的情況只有2個方向, p=(2^n-2)/2^n
class Ants {
public:
double antsCollision(int n) {
// write code here
int t = 1<<n;
return (t-2)*1.0/t;
}
};
給定一個int n(3<=n<=10000),代表n邊形和n只螞蟻,請返回一個double,爲相撞的概率。
分析:總共有2^n可能,不相碰的情況只有2個方向, p=(2^n-2)/2^n
class Ants {
public:
double antsCollision(int n) {
// write code here
int t = 1<<n;
return (t-2)*1.0/t;
}
};
C++ Primer 學習中。。。 簡單記錄下我的學習過程 (代碼爲主) 所有容器適用--------把數據從一個容器copy到另一個容器 //或者同一個容器中不同區間間的copy copy()