If the idea is to calculate the timing of the three coincidence, it will make the puzzle become very complex, the specific mathematical analysis can also look at the following Web site.
http://www.planetseed.com/node/18560
But here, with a simple idea, a change of mind, the program can be written very simply, as follows:
Ideas:
1 first to resolve the hand and the minute hand coincidence problem, such as my previous blog, you can see 12 hours overlap 12 times (count up two times).
2 then the question is converted into the time of the 12 encounters, is there a time in which the scoring needle and the second hand coincide (or are the hand and the second hand coincident)?
Using this idea we can get the following C + + programs:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
struct HMS
{
int hour;
int minute;
int second;
HMS (int h=0, int m=0, int s=0): Hour (h), Minute (m), second (s) {}
};
HMS sectohour (int s)
{
int h = s/3600;
s%= 3600;
int m = S/60;
s%=;
Return HMS (H, M, s);
}
void Meettime (vector<int> &mt)
{
Double vs = 1.0;
Double vm = 1.0/60.0;
Double VH = 1.0/60.0/12;
for (int i = 1; i < i++)
{
int a = i*60.0/(VM-VH);
if (Fmod (VS-VH) * A, 60.0) <= 1) mt.push_back (a);
}
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus/
Validation Program:
#include "Tick.h"
int main ()
{
vector<int> mt;
Meettime (MT);
HMS HMS;
for (int i = 0; i < mt.size (); i++)
{
HMS = Sectohour (Mt[i]);
cout<<mt[i]<< "-<
Output results:
Therefore, the puzzle solved, we do not have to find the answer on the Internet, also need not guess, here has been verified by the program.