首页 > ACM题库 > HDU-杭电 > hdu 2180 时钟-概率-[解题报告]C++
2013
12-30

hdu 2180 时钟-概率-[解题报告]C++

时钟

问题描述 :

从a点b分到s点t分时针和分针重合多少次?

输入:

有多组数据,每组1行4个数 a,b,s,t. 1<=a,s <=12, 0<=b,t<60. 0 0 0 0结束.

输出:

有多组数据,每组1行4个数 a,b,s,t. 1<=a,s <=12, 0<=b,t<60. 0 0 0 0结束.

样例输入:

12 50 1 2 
3 8 3 20 
2 45 11 0 
11 0 3 20 
1 2 12 50 
3 20 3 8
0 0 0 0

样例输出:

0
1
8
4
11
10

#include<iostream>
using namespace std;
int main()
{
    int a,b,s,t,i,j,k;
    while(cin>>a>>b>>s>>t && (a || b || s || t))
    {
        if(a>s || (a==s && b>=t)) s+=12;
        k=0;
        for(i=0;;i++)
        {
            j=(a+i)%12;
            if(a+i>s || (a+i==s && j*6>t*1.1)) break;
            if(j<11 && (i || j*6>=b*1.1)) 
            {
                k++;
            }
        }
        cout<<k<<endl;
    }
    return 0;
}

  1. 我还有个问题想请教一下,就是感觉对于新手来说,递归理解起来有些困难,不知有没有什么好的方法或者什么好的建议?

  2. Excellent Web-site! I required to ask if I might webpages and use a component of the net web website and use a number of factors for just about any faculty process. Please notify me through email regardless of whether that would be excellent. Many thanks