UVa 579 Clock Hands

水题。。

求任意时刻时针和分针的夹角,其结果在0°到180°之间。

这里又一次用到了sscanf()函数,确实很方便。

思路:我们分别求出时针和分针转过的角度,然后大的减小的,如果结果ans大于180,那么ans = 360 - ans。

  ClockHands 

The medieval interest in mechanical contrivances is well illustrated by the development of the mechanical clock, the oldest of which is driven by weights and controlled by a verge, an oscillating arm engaging with a gear wheel. It dates back to 1386.

Clocks driven by springs had appeared by the mid-15th century, making it possible to con- struct more compact mechanisms and preparing the way for the portable clock.

English spring-driven pendulum clocks were first commonly kept on a small wall bracket and later on a shelf. Many bracket clocks contained a drawer to hold the winding key. The earliest bracket clocks, made for a period after 1660, were of architectural design, with pillars at the sides and a pediment on top.

In 17th- and 18th-century France, the table clock became an object of monumental design, the best examples of which are minor works of sculpture.

The longcase clocks (also called grandfather clocks) are tall pendulum clock enclosed in a wooden case that stands upon the floor and is typically from 6 to 7.5 feet (1.8 to 2.3 m) in height. Later, the name ``grandfather clock‘‘ became popular after the popular song "My Grandfather‘s Clock," written in 1876 by Henry Clay Work.

One of the first atomic clocks was an ammonia-controlled clock. It was built in 1949 at the National Bureau of Standards, Washington, D.C.; in this clock the frequency did not vary by more than one part in 108

Nuclear clocks are built using two clocks. The aggregate of atoms that emit the gamma radiation of precise frequency may be called the emitter clock; the group of atoms that absorb this radiation is the absorber clock. One pair of these nuclear clocks can detect energy changes of one part in 1014 , being about 1,000 times more sensitive than the best atomic clock.

The cesium clock is the most accurate type of clock yet developed. This device makes use of transitions between the spin states of the cesium nucleus and produces a frequency which is so regular that it has been adopted for establishing the time standard.

The history of clocks is fascinating, but unrelated to this problem. In this problem, you are asked to find the angle between the minute hand and the hour hand on a regular analog clock. Assume that the second hand, if there were one, would be pointing straight up at the 12. Give all angles as the smallest positive angles. For example 9:00 is 90 degrees; not -90 or 270 degrees.

Input

The input is a list of times in the form H:M, each on their own line, with  and . The input is terminated with the time 0:00. Note that H may be represented with 1 or 2 digits (for 1-9 or 10-12, respectively); M is always represented with 2 digits (The input times are what you typically see on a digital clock).

Output

The output displays the smallest positive angle in degrees between the hands for each time. The answer should between 0 degrees and 180 degrees for all input times. Display each angle on a line by itself in the same order as the input. The output should be rounded to the nearest 1/1000, i.e., three places after the decimal point should be printed.

Sample Input

12:00
9:00
8:10
0:00

Sample Output

0.000
90.000
175.000

Miguel A. Revilla 
1998-03-10

AC代码:

 1 //#define LOCAL
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <algorithm>
 6 using namespace std;
 7
 8 int main(void)
 9 {
10     #ifdef LOCAL
11         freopen("579in.txt", "r", stdin);
12     #endif
13
14     int h, m;
15     char c[10];
16     while(gets(c))
17     {
18         sscanf(c, "%d:%d", &h, &m);
19         if(h == 0 && m == 0)
20             break;
21         if(h == 12)//12点不方便处理,转化为0点
22             h = 0;
23         double angle1, angle2, ans;
24         angle1 = h * 30 + (double) m / 2;
25         angle2 = m * 6;
26         ans = max(angle1, angle2) - min(angle1, angle2);
27         if(ans > 180)
28             ans = 360 - ans;
29         printf("%.3lf\n", ans);
30     }
31     return 0;
32 }

代码君

UVa 579 Clock Hands

时间: 2024-08-04 18:55:16

UVa 579 Clock Hands的相关文章

UVA 1529 - Clock(数论)

题目链接:1529 - Clock 题意:给定两个时刻,求时针和分针相遇次数. 思路:先把转一圈会相遇的时刻记录下来,这些时刻肯定是固定的,然后由给定的两个时刻a,b,求出12点到a相遇次数c1,12点到b相遇次数c2,ans = c2 - c1 代码: #include <stdio.h> #include <string.h> const double esp = 1e-6; int h1, m1, h2, m2; double t1, t2, s[25]; int main(

uva 1529 - Clock(数论)

题目链接:uva 1529 - Clock 题目大意:给出两个时间,问从第一个时间变成第二个时间分针会和时针重叠几次. 解题思路:两个针重叠的时间是固定的,只要处理出这些重叠的时刻,在判断说给得时间区间包含的个数即可. #include <cstdio> #include <cstring> #include <cmath> const int T = 12 * 60 * 100; const int D = 6545; int sh, sm, eh, em; int

UVa 170 - Clock Patience

题目:Clock Patience游戏,将52张扑克牌,按时钟依次分成13组(中心一组),每组4张全都背面向上, 从中间组最上面一张牌开始,翻过来设为当前值,然后取当前值对应组中最上面的背过去的牌翻过来, 取这个值为新的当前值,直到不能翻拍游戏结束:求结束时,翻过来的拍数以及最后翻过来的牌: 如果没看明白题目具体规则,百度玩一下就明白了. 分析:模拟,数据结构(DS).设计13个栈,模拟即可. 说明:注意题目给的牌的顺序是逆序的,╮(╯▽╰)╭. #include <algorithm> #i

UVa 11650 - Mirror Clock

题目:求给定时钟的镜面时间. 分析:简单题.直接用12:00减去当前时间即可,如果小时小于等于0加上12. 说明:没有0:01,只有12:00. #include <iostream> #include <cstdlib> #include <cstdio> using namespace std; int main() { int n,h,m,a,b; while (~scanf("%d",&n)) for (int i = 0 ; i &

uva 753 A Plug for UNIX (最大流)

uva 753 A Plug for UNIX You are in charge of setting up the press room for the inaugural meeting of the United Nations Internet eXecutive (UNIX), which has an international mandate to make the free flow of information and ideas on the Internet as cum

UVa 12325 - Zombie&#39;s Treasure Chest-[分类枚举]

12325 Zombie’s Treasure Chest Some brave warriors come to a lost village. They are very lucky and find a lot of treasures and a big treasure chest, but with angry zombies. The warriors are so brave that they decide to defeat the zombies and then brin

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f