Current location - Training Enrollment Network - Mathematics courses - How to solve a simple mathematical problem with C++
How to solve a simple mathematical problem with C++
Under normal circumstances, the hour hand turns one turn and the minute hand turns 12 turn; In this way, the speed of the minute hand is 12 times that of the hour hand.

Assuming that the hour hand turns to angle A and the minute hand turns to angle B, there is:12 * A = B. (where A is 0 to 360 degrees and B is 0 to 4320 degrees; In this way, people actually look at their watches not at 4320 degrees, but at b=bb+n*360 degrees, where bb is 0 to 360 degrees, which is exactly a circle, and N is 0 to 1 1).

Then, the above passage means that the normal visual relationship between the hour hand and the minute hand is: 12*a=b-n*360.

Now the hour hand and the minute hand are reversed, so substitute a= 12b into the formula (12*a=b-n*360) to get: 143b=-n*360, because the relationship of one revolution is relative, and this formula is 143b=.

Then all correct times are the solutions of 143b=n*360, where n = 0, 1, 2, ..., 142. (Because b can take 360 degrees, n here can also take 143, that is, in/. )

Therefore, there is an integer solution only when n=0, and it is non-integer at other times, even if it is extremely accurate. (The calculation angle of B is the angle of the hour hand relative to the hour of 12, and it can't be equal even if it is wonderfully accurate. )

So, you can't solve other schemes.

If we use approximate equations for this problem, we may find a solution.

I made a program as follows: (The program found the result of 144, but the last one had a problem, so I brought it right away, which was actually the same as the first one. Please contact me if you have any questions.)

# include "iostream "// The author is sxt 198402 10, which was built at 7:20 on February 27th, 2009.

Use namespace std

void main()

{

int h,m,s,c,k; //Real-time: h = hours, m = minutes, s = seconds, and c = (112) seconds.

int mh,mm,ms; //"hour hand" time: a fake hour hand and an hour hand walking at the minute hand speed; A reference means an error.

int hm,hs,HC; //"Minute hand" time: false minute hand, minute hand walking at clockwise speed; A reference means an error.

k = 0;

Cout & lt& lt\ t'<& lt "real-time"

for(h = 0; h & lt 12; H++)// Record real-time time.

{

for(m = 0; m & lt60; M++)// Record the real minute time.

{

for(s = 0; s & lt60; S++)// Record the real wonderful clock time.

{

for(c = 0; c & lt 12; C++)// is used to record112 seconds. The "hour hand" moves at real 1 sec11sec; "Minute hand" goes 12 seconds 1 second.

{

MH =(int)m/5; //The current "hour hand" (real minute hand, 60 minutes per lap) represents 12 hours per lap, and the pointer is 1/5 of the minute hand.

mm = m % 5 * 12+(int)s/5; //At this time, the number of minutes indicated by the "hour hand" is also 12 times, and the number of seconds is also 1/5.

ms = s % 5 * 12+c; //When the "hour hand" is true, the indicated number of seconds is 1 sec, and here it will take 1 sec, and1sec will take1sec.

hm = h * 5+(int)m/ 12; //"Minute hand" (true hour, each lap 12 hours) is now 1 hour, and the relationship with true hours and minutes is five times, which is112.

hs = m % 12 * 5+(int)s/ 12; //The second represented by "minute" has a five-fold relationship with the real minute, and the relationship with the real second is112.

HC = s % 12 * 12+c; //1144 seconds, expressed in "minutes"

if((mm = = hm)& amp; & (ms = = hs))//If the minute and second indicated by the "hour hand" are the same as those indicated by the "minute", it is qualified.

{

k++;

cout & lt& ltk & lt& lt\ t ';

cout & lt& lth & lt& lt:' & lt& ltm & lt& lt:' & lt& lts & lt& lt\ t ' & lt& lt\ t ' & lt& ltmh & lt& lt:' & lt& ltmm & lt& lt:' & lt& ltms & lt& lt\ t ' & lt& lt\ t ' & lt& lthc & lt& ltendl

If (hc==0)

Cout & lt& lt "The above time is an integer solution!" & lt& ltendl

}

}

}

}

}

}