1. Title Description: Click to open the link
2. Problem solving ideas: the topic belongs to probability theory. According to test instructions description, it is advisable to first find out the last two people to eat a different burger probability, set it to P. So easy to know, the front n-2 individuals, there are n/2-1 individuals eat beef fort, the rest of the people eat chicken fort. therefore p[n]= (0.5) ^ (n-2) *c (n-2,n/2-1). The final answer is 1-p. However, you can find that p can be recursive, so you can calculate all the P-values in advance, and then output the answer directly.
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std; #define MAXN 100010double dp[maxn];void Init () {dp[2] = 1;for (int i = 2; i<maxn; i++) Dp[i + 2] = dp[i] * 1.0* (I-1)/(double) (i);} int main () {//freopen ("T.txt", "R", stdin), int T, N;init (), scanf ("%d", &t), while (t--) {scanf ("%d", &n);p rintf (" %.4lf\n ", 1-dp[n]);} return 0;}
Exercise 10-12 Hamburg UVa557