24h購物| | PChome| 登入
2012-11-20 07:33:31| 人氣1,357| 回應0 | 上一篇 | 下一篇

[UVA][模擬] 12531 - Hours and Minutes

推薦 0 收藏 0 轉貼0 訂閱站台

Heidi has a discrete analog clock in the shape of a circle, as the one in the figure. Two hands rotate around the center of the circle, indicating hours and minutes. The clock has 60 marks placed around its perimeter, with the distance between consecutive marks being constant.

The minute hand moves from its current mark to the next exactly once every minute. The hour hand moves from its current mark to the next exactly once every 12 minutes, so it advances five marks each hour.

We consider that both hands move discretely and instantly, which means they are always positioned exactly over one of the marks and never in between marks.

epsfbox{p12531.eps}

At midnight both hands reach simultaneously the top mark, which indicates zero hours and zero minutes. After exactly 12 hours or 720 minutes, both hands reach the same position again, and this process is repeated over and over again. Note that when the minute hand moves, the hour hand may not move; however, when the hour hand moves, the minute hand also moves.

Heidi likes geometry, and she likes to measure the minimum angle between the two hands of the clock at different times of the day. She has been writing some measures down, but after several years and a long list, she noticed that some angles were repeated while some others never appeared. For instance, Heidi's list indicates that both at three o'clock and at nine o'clock the minimum angle between the two hands is 90 degrees, while an angle of 65 degrees does not appear in the list. Heidi decided to check, for any integer number A between 0 and 180, if there exists at least one time of the day such that the minimum angle between the two hands of the clock is exactly A degrees. Help her with a program that answers this question.

Input 

Each test case is described using one line. The line contains an integer A representing the angle to be checked ( 0$ le$A$ le$180).

Output 

For each test case output a line containing a character. If there exists at least one time of the day such that the minimum angle between the two hands of the clock is exactly A degrees, then write the uppercase letter `Y'. Otherwise write the uppercase letter `N'.

Sample Input 

90
65
66
67
128
0
180

Sample Output 

Y
N
Y
N
N
Y
Y

注意 m/12*6 !=m/2

#include <stdio.h>
#include <stdlib.h>
int main() {
    int h, m;
    int used[181] = {};
    for(h = 0; h < 12; h++) {
        for(m = 0; m < 60; m++) {
            int deg1 = h*30 + m/12*6;
            int deg2 = m*6;
            int app = abs(deg1-deg2);
            if(app > 180)   app = 360 - app;
            used[app] = 1;
        }
    }
    while(scanf("%d", &h) == 1) {
        puts(used[h] ? "Y" : "N");
    }
    return 0;
}

台長: Morris
人氣(1,357) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][dp] 10453 - Make Palindrome
此分類上一篇:[UVA][烏龜塔] 10154 - Weights and Measures

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文