C + + program verification: One day the hour, minute and second hand overlap puzzles

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.