Unraveling Monty Hall

On the stage of an auditorium program there are three closed doors: door 1, door 2 and door 3. Behind one of these doors there is a car and behind the other two doors there is a goat. The production of the program randomly chooses the door where the car is without cheating. Only the host of the program knows where the car is. He asks the player to choose one of the doors. We can see that, because there is only one car, and at at least one of the two doors that the player did not choose, there has to be a goat!

Therefore, the presenter can always do the following: between the two doors that the Player did not choose, he opens one that has a goat, so that the player and the spectators can see the goat. The presenter now asks: “Do you want to change your door to the other door that is still closed?”. Is it a beneficial change or not? The player wants to stay with the door that has the car, of course!

Paulinho saw a rigorous demonstration that the odds of the car being behind door the player chose initially is 1/3 and the odds of the car being behind the other door which is still closed and the player did not choose initially is 2/3 and therefore the exchange is advantageous. Paulinho doesn’t conform, his intuition tells him that either way, the probability is 1/2 for both doors still closed.

To bring this matter to an end, let’s simulate this game thousands of times and count how many times the player won the car. We will assume that:

The player picks door 1 initially;
The player always changes doors after the presenter reveals a goat by opening one of the two doors that were not initially selected.
In these conditions, in a game, given the number of the door that contains the car, we can know exactly whether the player will win the car or not.

Input
The first line of the input contains an integer N (1≤N≤10^4), indicating the number of games in the simulation. Each of the N following rows contains an integer: 1, 2 or 3; representing the door number containing the car in that game.

Output
Your program must produce a single line containing an integer representing the number of times the player won the car in this simulation, assuming that he always chooses the door 1 and always switch doors after the host reveals a goat by opening one of the two doors that were not initially selected.

Examples
Input
5
1
3
2
2
1
Output
3

Input
1
1
Output
0
Input
15
3
2
3
1
1
3
3
2
2
1
2
3
2
1
1
Output
10
有三个门,一个门后有车,一个门后有羊,一个门后什么也没有,emmmmmm忘了
难点就是题意理解
理解完之后发现其实就是求不是1的数(2和3)的个数

#include
using namespace std;
int main(){
	int n,x;
	while(~scanf("%d",&n)){
		int ans=0;//记录1的个数
		for(int i=1;i<=n;i++){
			scanf("%d",&x);
			if(x==1) ans++;
		}
		printf("%d\n",n-ans);//总数减去1的个数就是所求的答案
	}
	return 0;
}

你可能感兴趣的:(阅读理解水题,Unraveling,Monty,Hall)