Posts

Showing posts from May, 2016

【USACO】Transformations

Problem A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations: # 1 : 90 Degree Rotation: The pattern was rotated clockwise 90 degrees. # 2 : 180 Degree Rotation: The pattern was rotated clockwise 180 degrees. # 3 : 270 Degree Rotation: The pattern was rotated clockwise 270 degrees. # 4 : Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image). # 5 : Combination: The pattern was reflected horizontally and then subjected to one of the rotations (# 1 -# 3 ). # 6 : No Change: The original pattern was not changed. # 7 : Invalid Transformation: The new pattern was not obtained by any of the above methods. In the case that more than one transf...

【USACO】Milking Cows

Problem Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer begins milking his cow at time 300 (measured in seconds after 5 am) and ends at time 1000. The second farmer begins at time 700 and ends at time 1200. The third farmer begins at time 1500 and ends at time 2100. The longest continuous time during which at least one farmer was milking a cow was 900 seconds (from 300 to 1200). The longest time no milking was done, between the beginning and the ending of all milking, was 300 seconds (1500 minus 1200). Your job is to write a program that will examine a list of beginning and ending times for N (1 <= N <= 5000) farmers milking N cows and compute (in seconds): The longest time interval at least one cow was milked. The longest time interval (after milking starts) during which no cows were being milked. PROGRAM NAME: milk2 INPUT FORMAT Line 1: The single integer, N Lines 2..N+1: Two non-negative integers less than 1,000,000...

【CodeForces】C. Drazil and Factorial

Image
Problem  here Problem Drazil is playing a math game with Varda. Let’s define   for positive integer x as a product of factorials of its digits. For example,  First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions: x doesn’t contain neither digit 0 nor digit 1. =  Help friends find such number. INPUT The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a. The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes. OUTPUT Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. Sample input 4  1234 output 33222 input 3  555 output 555 ...

【CodeForces】A. Pouring Rain

Image
Problem  here Problem A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of w...