I. BACKGROUND
The Golden Dot game is a digital mini-game whose game rules are:
n classmates (n usually greater than ten), each person writes a rational number between 0~100 ( excluding 0 or three), gives the referee, the referee calculates the average of all the numbers, and then multiplies the 0.618 (The so-called Golden Section constant), get the G value. The number of the submitted nearest to G(absolute value) of the students get n points, the farthest from the G students get-2 points, the other students get 0 points. after a few days of playing, we found some interesting phenomena, such as the golden dots moving down gradually.
Now please according to the rules of the game, make up a can play with a number of small game program, the requirements are as follows:
1, this job belongs to the pair programming project, must be completed by two people, and will be sent to the blog, respectively, the operation of the source code submitted to the codeing system;
2, if possible to use the C/s or b/n as much as possible, that is, using the server to receive and process all the players submitted by the number, and the results back to the players, players can be submitted by the client number;
3, if the use of single-machine approach, it is necessary to provide users with convenient input interface;
4, the game can run at least 10 rounds at a time, and can keep the results of the rounds.
Second, analysis
This little game, you're going to think, if you get a random count,
Start of the first round: may be true random, the average of 0-100 is 50, 50 * 0.618 = 31. Then I'm going to have a 31.
The second round starts: when everybody gradually understood the game bug, but they certainly also thought to choose 31 near, if everybody all choose 31 near the number, then I must choose 31*0.618 = 19;
The third round and then the ...
But these people must have thought of it, so I'm going to choose 19 * 0.618 = 12 ... Then 12 * 0.618 = 8
。。。。。。。。
Finally, simply select the smaller number, for example 0.00000000001, which is a rational number.
is 0.00000000001 the right answer? This depends on all members participating in the game.
When the game's people are programmers or people with high IQ, the game will indeed appear as we predicted before, the value of the G-spot is declining.
But if it is a group of knowledge for the fun of the small partner, then the result will be a variety of situations, the results are not predictable, but you carefully observe that the size of the G value is not determined by the few, but by the majority of people decide. The most frightening is the reverse retrograde game players finally "compliance" to submit a large number, and finally your score is negative, another round, you are not a fool, you will make your own number small enough to go out of their own is-2 points of the situation.
The golden ratio of 0.618, in life, learning can often be seen, the golden ratio is divided into two parts of a line segment, so that the ratio of part to full length is equal to the other part of the ratio. The ratio is an irrational number, and the approximate value of the first three digits is 0.618. The so-called Golden Division, refers to the length of the line is divided into two parts, so that part of the ratio of all, equal to the other part of the ratio of the part. The simplest way to calculate the Golden section is to calculate the Fibonacci sequence 1,1,2,3,5,8,13,21, ... The ratio of the latter two 2/3,3/5,4/8,8/13,13/21,... Approximate value.
Three, easy wrong point
It is considered an integer before the program automatically stops when the rational number is entered. When the Chinese name appears in the program can be stored, when the map is not empty ...
Easy-to-appear error (1): is a rational number, not an integer
Causes and solutions: Change map<string,int>mp;--->map<string,double>mp; this is where map is very flexible and you can define your own data types.
Easy Error (2): When the number of games is not changed, people can still play
Causes and solutions: each time the sum, the average, the G value is emptied.
Prone errors (3): Every game starts with a new start when the person's name changes
Solution: Your map is not emptied every time, using the function clear () in map, the statement is emptied using mp.clear ().
When the person in the first round is different from the person in the second round, the map saves the desired
Easy error Point (4): Each round of input can not follow a certain sequence of input, but the map is ultimately the output of the map dictionary sequence,
Causes and solutions: The map also has the advantage of automatically sorting the first field. So in the game can be when some people have not thought good to hand over what data, can skip, will not affect the results.
When the data you select is getting smaller, the G value will indeed gradually decrease.
Four, pair programming photos (Ps: serious handsome Beautiful)
V. Summary and Evaluation
This time pair programming, can be said not their first pair programming, in ACM is often a programming, one person review, another person to provide ideas, and then cross-rotating programming, turn code review, so programming efficiency, not error-prone, and can be programmed by pairing, Familiar with the partner's programming style and thinking mode, but also for their own shortcomings in a place to improve. is a way to learn from each other, only the pair programming of the two people's programming level together, but there is such a situation, you do not want to programming with him, will only let each other Maitai, and then low efficiency.
To the teammate's evaluation: after understanding test instructions, own idea is uses the STL map, the time complexity Logn, I first the map establishment and the data input carries on the simple test, then writes to the multi-wheel game the beginning completes. But she gave me one. If you want to show the results after multiple rounds, she says, he can define another map variable, which can be used to save every score and accumulate it.
Vi. Source code (use the software code Block, compiled by the GCC compiler)
#include <iostream>#include<cstdio>#include<cstdlib>#include<map>using namespacestd;intMain () {intGame_num; Map<string,Double>MP; intI,n; DoubleNum,sum,ave; intg,temp=0; stringname; printf ("Please enter the number of games:"); scanf ("%d",&N); printf ("\ n"); printf ("Please enter the number of rounds for this game:"); scanf ("%d",&game_num); printf ("\ n"); while(game_num--) { ++temp; Mp.clear (); //empty the data in the mapsum=0; ave=0; g=0; printf ("start of the first round of%d: \ n", temp); printf ("Please enter each person's name and rational number (space separated): \ n"); for(i=0; i<n;i++) {cin>>name>>num; if(num>0.0&&num<100.0) {Mp[name]=num;//establishing a map relationshipsum=sum+num; } Else{printf ("Please enter a rational number (0-100) \ n"); I--; }} Map<string,Double>:: Iterator Iter,result_high,result_low; printf ("The sum is:%.4lf\n", sum); Ave=sum/N; printf ("Average:%.4lf\n", Ave); G=ave*0.618; printf ("g point value:%.4lf\n", G); for(Iter=mp.begin (); Iter!=mp.end (); iter++) {iter->second = (int) ABS (g (int) iter->second);//the difference in the existence of ITER } for(Iter=mp.begin (), Result_high=mp.begin (), Result_low=mp.begin (); Iter!=mp.end (); iter++) { if(iter->second<result_high->second) Result_high=ITER; if(iter->second>result_low->second) Result_low=ITER; } cout<<Endl; cout<<"name"<<"\ t"<<"Difference Value"<<Endl; cout<<result_high->first<<"\ t"<<result_high->second<<"\ t"<<"Get"<<n<<"points"<<Endl; cout<<result_low->first<<"\ t"<<result_low->second<<"\ t"<<"get-2 points"<<Endl; cout<<Endl; for(Iter=mp.begin (); Iter!=mp.end (); iter++) {iter->second =0; } for(Iter=mp.begin (); Iter!=mp.end (); iter++) { if(iter==Result_high) ITER->second+=N; if(iter==Result_low) ITER->second+=-2; } cout<<"Section"<<temp<<"Round results:"<<Endl; cout<<"name"<<"\ t"<<"score"<<Endl; for(Iter=mp.begin (); Iter!=mp.end (); iter++) cout<<iter->first<<"\ t"<<iter->second<<Endl; cout<<Endl; } return 0;}
If there are errors in the text, please help to point out that we can discuss together and improve together.
Data
Software Engineering-the method of construction the Golden Dot mini-game