又开始捡起自己的算法练习篇~~
1006 Tick and Tick
Problem Description
1 | The three hands of the clock are rotating every second and meeting each other many times everyday. Finally, they get bored of this and each of them would like to stay away from the other two. A hand is happy if it is at least D degrees from any of the rest. You are to calculate how much time in a day that all the hands are happy. |
Input
1 | The input contains many test cases. Each of them has a single line with a real number D between 0 and 120, inclusively. The input is terminated with a D of -1. |
Output
1 | For each D, print in a single line the percentage of time in a day that all of the hands are happy, accurate up to 3 decimal places. |
Sample Input
1 | 0 |
Sample Output
1 | 100.000 |
题意: 时钟的三个指针,在他们之间的角度大于D度时,可以认为是happy,求一天中的happy时间占的百分比
分析:由于12小时后,时针、分针、看到这个首先想到的追击与相遇问题,我们可以将时、分、秒针的速度统一单位,然后可以求出相对速度。得到相对速度之后单独对两个针分析(由于是三个角度都需要大于D),由此得到两针相差一度所需要的时间,那么最晚达到D度和最早结束D度之间的区间时间就是happy-time
,然后就考虑周期的问题,但最早结束的应该转到下一个满足条件状态(加上一个周期)。最后记得我们是勇12小时来计算的,即43200s
代码
1 |
|
1007 Quoit Design
Problem Description
1 | Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded. |
Input
1 | The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated by N = 0. |
Output
1 | For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places. |
Sample Input
1 | 2 |
Sample Output
1 | 0.71 |
1 | /* |
1008 Elevator
Problem Description
1 | The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop. |
Input
1 | There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed. |
Output
1 | Print the total time on a single line for each test case. |
Sample Input
1 | 1 2 |
Sample Output
1 | 17 |
题意
一个楼梯用于升降,第一个N数为请求数量,随后跟着N个请求,对于上升请求,每上一楼6秒,停5秒,对于下降请求,每下一楼4秒,停5秒。
代码
1 |
|
1009 FatMouse’ Trade
Problem Description
1 | FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. |
Input
1 | The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1’s. All integers are not greater than 1000. |
Output
1 | For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain. |
Sample Input
1 | 5 3 |
Sample Output
1 | 13.333 |
题意
M吨猫粮,
分析
尝试贪心
代码
1 |
|
1010 Tempter of the Bone
Problem Description
1 | The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze. |
Input
1 | The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following: |
Output
1 | For each test case, print in one line “YES” if the doggie can survive, or “NO” otherwise. |
Sample Input
1 | 4 4 5 |
Sample Output
1 | NO |