Você está na página 1de 8

Mastermind is a game of two players. In the beginning, first player decides a secret key, which is a sequence (s1,s2,...

sk) where 0 < si <= n, Then second player makes guesses in rounds, where each guess is of form (g1,g2, ...gk), and after each guess first player calculates the score for the guess. Score for a guess is equal to number of i's for which we have gi = si. For example if the secret key is (4,2,5,3,1) and the guess is (1,2,3,7,1),then the score is 2, because g2 = s2 and g5 = s5. Given a sequence of guesses, and scores for each guess, your program must decide if there exists at least one secret key that generates those exact scores. Input First line of input contains a single integer C (1 <=C <= 100). C test-cases follow. First line of each test-case contains three integers n,k and q. (1 <=n,k <=11, 1<=q<=8). Next q lines contain the guesses. Each guess consists of k integers gi,1, gi,2,....gi,k separated by a single space, followed by the score for the guess bi (1 <= gi,j <=n for all 1 <=i <=q, 1 <=j <=k; and 0 <= bi <=k ) Output For each test-case, output "Yes" (without quotes), if there exists at least a secret key which generates those exact scores, otherwise output "No". Sample Input 2 442 21220 22111 442 12344 43211 Sample Output Yes No

One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input The first (and the only) input line contains integer number w (1w100) the weight of the watermelon bought by the boys. Output Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Sample test(s) Input
8

Output
YES

Note For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant two parts of 4 and 4 kilos).

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers!

Input
The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.

Output
For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.

Example
Input: 2 1 10 3 5 Output: 2 3 5 7 3 5

The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, he wants to get from his current position s to square t in the least number of moves. Help him to do this.

In one move the king can get to the square that has a common side or a common vertex with square the king is currently in (generally there are 8 different squares he can move to). Input The first line contains the chessboard coordinates of square s, the second line of square t. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. Output In the first line print n minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.

L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2letter combinations stand for diagonal moves. If the answer is not unique, print any of them. Sample test(s) Input
a8 h1

Output
7 RD RD RD RD RD RD RD

Given two vessels, one of which can accommodate a litres of water and the other - b litres of water, determine the number of steps required to obtain exactly c litres of water in one of the vessels. At the beginning both vessels are empty. The following operations are counted as 'steps':

emptying a vessel, filling a vessel, pouring water from one vessel to the other, without spilling, until one of the vessels is either full or empty.

Input
An integer t, 1<=t<=100, denoting the number of testcases, followed by t sets of input data, each consisting of three positive integers a, b, c, not larger than 40000, given in separate lines.

Output
For each set of input data, output the minimum number of steps required to obtain c litres, or -1 if this is impossible.

Example
Sample input:
2 5 2 3 2 3 4

Sample output:
2 -1

Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input The only line of the input file contains two natural numbers Y and W the results of Yakko's and Wakko's die rolls. Output Output the required probability in the form of irreducible fraction in format A/B, where A the numerator, and B the denominator. If the required probability equals to zero, output 0/1. If the required probability equals to 1, output 1/1. Sample test(s) Input
4 2

Output
1/2

Note Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points

The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most lucky for him distribution of price tags) and the largest total price (in case of the most unlucky for him distribution of price tags). Input The first line of the input contains two integer number n and m (1n,m100) the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (ab) the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Sample test(s) Input
5 3 4 2 1 10 5 apple orange mango

Output
7 19

Input
6 5 3 5 1 6 8 1 peach grapefruit banana orange orange

Output
11 30

As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n-1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads. The Two Paths company, where Bob's brother works, has won a tender to repair two paths in Flatland. A path is a sequence of different cities, connected sequentially by roads. The company is allowed to choose by itself the paths to repair. The only condition they have to meet is that the two paths shouldn't cross (i.e. shouldn't have common cities). It is known that the profit, the Two Paths company will get, equals the product of the lengths of the two paths. Let's consider the length of each road equals 1, and the length of a path equals the amount of roads in it. Find the maximum possible profit for the company. Input The first line contains an integer n (2n200), where n is the amount of cities in the country. The following n-1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road ai,bi (1ai,bin). Output Output the maximum possible profit. Sample test(s) Input
4 1 2 2 3 3 4

Output
1

Input
7 1 1 1 1 1 1 0 2 3 4 5 6 7

Output Input
6 1 2 2 5 6 2 3 4 4 4

Output
4

Você também pode gostar