A + B Again

Problem Description
There must be many A + B problems in our HDOJ , now a new one is coming.
Easy ? AC it !

Input
The input contains several test cases, please process to the end of the file.
Each case consists of two hexadecimal integers A and B in a line seperated by a blank.
The length of A and B is less than 15.

Output
For each test case,print the sum of A and B in hexadecimal in one line.

Sample Input
+A -A
+1A 12
1A -9
-1A -12
1A -AA

Sample Output
0
2C
11
-2C
-90

1个回答

A + B Again
Problem Description There must be many A + B problems in our HDOJ , now a new one is coming. Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too. Easy ? AC it ! Input The input contains several test cases, please process to the end of the file. Each case consists of two hexadecimal integers A and B in a line seperated by a blank. The length of A and B is less than 15. Output For each test case,print the sum of A and B in hexadecimal in one line. Sample Input +A -A +1A 12 1A -9 -1A -12 1A -AA Sample Output 0 2C 11 -2C -90
Farey Sequence Again
Problem Description The Farey sequence Fn for any positive integer n is the set of irreducible rational numbers a/b with 0<a<b<=n and (a, b) = 1 arranged in increasing order. Here (a, b) mean the greatest common divisor of a and b. For example: F2 = {1/2} F3 = {1/3, 1/2, 2/3} Given two positive integers N and K, with K less than N, you need to find out the K-th smallest element of the Farey sequence FN. Input The first line of input is the number of test case T, 1<=T<=1000. Then each test case contains two positive integers N and K. 1<=K<N<=10^9. Output For each test case output the Kth smallest element of the Farey sequence FN in a single line. Sample Input 3 2 1 100 68 101 69 Sample Output 1/2 2/83 1/42
Vive la Difference! 怎么实现的
roblem Description Take any four positive integers: a, b, c, d. Form four more, like this: |a-b| |b-c| |c-d| |d-a| That is, take the absolute value of the differences of a with b, b with c, c with d, and d with a. (Note that a zero could crop up, but they’ll all still be non-negative.) Then, do it again with these four new numbers. And then again. And again. Eventually, all four integers will be the same. For example, start with 1,3,5,9: 1 3 5 9 2 2 4 8 (1) 0 2 4 6 (2) 2 2 2 6 (3) 0 0 4 4 (4) 0 4 0 4 (5) 4 4 4 4 (6) In this case, the sequence converged in 6 steps. It turns out that in all cases, the sequence converges very quickly. In fact, it can be shown that if all four integers are less than 2^n, then it will take no more than 3*n steps to converge! Given a, b, c and d, figure out just how quickly the sequence converges. Input There will be several test cases in the input. Each test case consists of four positive integers on a single line (1 ≤ a,b,c,d ≤ 2,000,000,000), with single spaces for separation. The input will end with a line with four 0s. Output For each test case, output a single integer on its own line, indicating the number of steps until convergence. Output no extra spaces, and do not separate answers with blank lines. Sample Input 1 3 5 9 4 3 2 1 1 1 1 1 0 0 0 0 Sample Output 6 4 0
A + B for you again
Problem Description Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition between them is “asdfg”, for “sdf” is the tail substring of “asdf” and the head substring of the “sdfg” . However, the result comes as “asdfghjk”, when you have to add “asdf” and “ghjk” and guarantee the shortest string first, then the minimum lexicographic second, the same rules for other additions. Input For each case, there are two strings (the chars selected just form ‘a’ to ‘z’) for you, and each length of theirs won’t exceed 10^5 and won’t be empty. Output Print the ultimate string by the book. Sample Input asdf sdfg asdf ghjk Sample Output asdfg asdfghjk
Farey Sequence Again 怎么写的
Problem Description The Farey sequence Fn for any positive integer n is the set of irreducible rational numbers a/b with 0<a<b<=n and (a, b) = 1 arranged in increasing order. Here (a, b) mean the greatest common divisor of a and b. For example: F2 = {1/2} F3 = {1/3, 1/2, 2/3} Given two positive integers N and K, with K less than N, you need to find out the K-th smallest element of the Farey sequence FN. Input The first line of input is the number of test case T, 1<=T<=1000. Then each test case contains two positive integers N and K. 1<=K<N<=10^9. Output For each test case output the Kth smallest element of the Farey sequence FN in a single line. Sample Input 3 2 1 100 68 101 69 Sample Output 1/2 2/83 1/42
It's not a Bug, It's a Feature! 具体实现
Problem Description It is a curious fact that consumers buying a new software product generally do not expect the software to be bug-free. Can you imagine buying a car whose steering wheel only turns to the right? Or a CD-player that plays only CDs with country music on them? Probably not. But for software systems it seems to be acceptable if they do not perform as they should do. In fact, many software companies have adopted the habit of sending out patches to fix bugs every few weeks after a new product is released (and even charging money for the patches). Tinyware Inc. is one of those companies. After releasing a new word processing software this summer, they have been producing patches ever since. Only this weekend they have realized a big problem with the patches they released. While all patches fix some bugs, they often rely on other bugs to be present to be installed. This happens because to fix one bug, the patches exploit the special behavior of the program due to another bug. More formally, the situation looks like this. Tinyware has found a total of n bugs B = {b1, b2, ..., bn} in their software. And they have released m patches p1, p2, ..., pm. To apply patch pi to the software, the bugs Bi+ in B have to be present in the software, and the bugs Bi- in B must be absent (of course Bi+ ∩ Bi- = Φ). The patch then fixes the bugs Fi- in B (if they have been present) and introduces the new bugs Fi+ in B (where, again, Fi+ ∩ Fi- = Φ). Tinyware's problem is a simple one. Given the original version of their software, which contains all the bugs in B, it is possible to apply a sequence of patches to the software which results in a bug- free version of the software? And if so, assuming that every patch takes a certain time to apply, how long does the fastest sequence take? Input The input contains several product descriptions. Each description starts with a line containing two integers n and m, the number of bugs and patches, respectively. These values satisfy 1 <= n <= 20 and 1 <= m <= 100. This is followed by m lines describing the m patches in order. Each line contains an integer, the time in seconds it takes to apply the patch, and two strings of n characters each. The first of these strings describes the bugs that have to be present or absent before the patch can be applied. The i-th position of that string is a ``+'' if bug bi has to be present, a ``-'' if bug bi has to be absent, and a `` 0'' if it doesn't matter whether the bug is present or not. The second string describes which bugs are fixed and introduced by the patch. The i-th position of that string is a ``+'' if bug bi is introduced by the patch, a ``-'' if bug bi is removed by the patch (if it was present), and a ``0'' if bug bi is not affected by the patch (if it was present before, it still is, if it wasn't, is still isn't). The input is terminated by a description starting with n = m = 0. This test case should not be processed. Output For each product description first output the number of the product. Then output whether there is a sequence of patches that removes all bugs from a product that has all n bugs. Note that in such a sequence a patch may be used multiple times. If there is such a sequence, output the time taken by the fastest sequence in the format shown in the sample output. If there is no such sequence, output ``Bugs cannot be fixed.''. Print a blank line after each test case. Sample Input 3 3 1 000 00- 1 00- 0-+ 2 0-- -++ 4 1 7 0-0+ ---- 0 0 Sample Output Product 1 Fastest sequence takes 8 seconds. Product 2 Bugs cannot be fixed.
Farey Sequence Again 程序编写的法则
Problem Description The Farey sequence Fn for any positive integer n is the set of irreducible rational numbers a/b with 0<a<b<=n and (a, b) = 1 arranged in increasing order. Here (a, b) mean the greatest common divisor of a and b. For example: F2 = {1/2} F3 = {1/3, 1/2, 2/3} Given two positive integers N and K, with K less than N, you need to find out the K-th smallest element of the Farey sequence FN. Input The first line of input is the number of test case T, 1<=T<=1000. Then each test case contains two positive integers N and K. 1<=K<N<=10^9. Output For each test case output the Kth smallest element of the Farey sequence FN in a single line. Sample Input 3 2 1 100 68 101 69 Sample Output 1/2 2/83 1/42
Cutting trees 程序怎么来做
Problem Description A rooted graph is an indirected graph with every edge attached by some path to a special vertex called the root or the ground. The ground is denoted in the below figures that follow by a dotted line. A bamboo stalk with n segments is a linear graph of n edges with the bottom of the n edges rooted to the ground. A move consists of hacking away one of the segments, and removing that segment and all segments above it no longer connectd to the ground. Two players alternate moves and the last player to move wins. A single bamboo stalk of n segments can be moved into a bamboo stalk of any smaller number of segments from n-1 to 0. So a single bamboo stalk of n segments is equivalent to a nim pile of n chips. As you known, the player who moves first can win the the game with only one bamboo stalk. So many people always play the game with several bamboo stalks. One example is as below: Playing a sum of games of bamboo stalks is thus equivalent to playing a nim game that with several piles. A move consisits of selecting a bamboo stalk containg n segments and hacking away one of the segments in the selected bamboo stalk. I think the nim game is easy for you, the smart ACMers. So, today, we play a game named "cutting trees". A "rooted tree" is a graph with a distinguished vertex called the root, with the property that from every vertex there is unique path(that doesn't repeat edges) to the root. Essentially this means there are no cycles. Of course, in the game "cutting trees", there are several trees.Again, a move consisits of selecting a tree and hacking away any segment and removing segment and anything not connected to the ground. The player who cuts the last segment wins the game. Input Standard input will contain multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each case begins with a N(1<=N<=1000), the number of trees in the game.A tree is decribed by a number m, the nodes of the tree and R(0<=R<=m-1), the root of the tree. Then m-1 lines follow, each line containg two positive integers A,B∈[0,m-1], means that there is a edge between A and B. In the game, the first player always moves first. Output Results should be directed to standard output. For each case, if the first player wins, ouput "The first player wins", or else, output "The second player wins",in a single line. Sample Input 1 1 4 0 0 1 1 2 1 3 Sample Output The first player wins
Crash and Go(relians) 怎么实现的
Calling Extraterrestrial Intelligence Again
Problem Description A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November 16, 1974. The message consisted of 1679 bits and was meant to be translated to a rectangular picture with 23 * 73 pixels. Since both 23 and 73 are prime numbers, 23 * 73 is the unique possible size of the translated rectangular picture each edge of which is longer than 1 pixel. Of course, there was no guarantee that the receivers would try to translate the message to a rectangular picture. Even if they would, they might put the pixels into the rectangle incorrectly. The senders of the Arecibo message were optimistic. We are planning a similar project. Your task in the project is to find the most suitable width and height of the translated rectangular picture. The term "most suitable" is defined as follows. An integer m greater than 4 is given. A positive fraction a / b less than or equal to 1 is also given. The area of the picture should not be greater than m. Both of the width and the height of the translated picture should be prime numbers. The ratio of the width to the height should not be less than a / b nor greater than 1. You should maximize the area of the picture under these constraints. In other words, you will receive an integer m and a fraction a / b. It holds that m > 4 and 0 < a / b < 1. You should find the pair of prime numbers p, q such that pq <= m and a / b <= p / q <= 1, and furthermore, the product pq takes the maximum value among such pairs of two prime numbers. You should report p and q as the "most suitable" width and height of the translated picture. Input The input is a sequence of at most 2000 triplets of positive integers, delimited by a space character in between. Each line contains a single triplet. The sequence is followed by a triplet of zeros, 0 0 0, which indicated the end of the input and should not be treated as data to be processed. The integers of each input triplet are the integer m, the numerator a, and the denominator b described above, in this order. You may assume 4 < m <= 100000 and 1 <= a <= b <= 1000. Output The output is a sequence of pairs of positive integers. The i-th output pair corresponds to the i-th input triplet. The integers of each output pair are the width p and the height q described above, in this order. Each output line contains a single pair. A space character is put between the integers as a delimiter. No other characters should appear in the output. Sample Input 5 1 2 99999 999 999 1680 5 16 1970 1 1 2002 4 11 0 0 0 Sample Output 2 2 313 313 23 73 43 43 37 53
Vive la Difference! 具体怎么写的呢
Problem Description Take any four positive integers: a, b, c, d. Form four more, like this: |a-b| |b-c| |c-d| |d-a| That is, take the absolute value of the differences of a with b, b with c, c with d, and d with a. (Note that a zero could crop up, but they’ll all still be non-negative.) Then, do it again with these four new numbers. And then again. And again. Eventually, all four integers will be the same. For example, start with 1,3,5,9: 1 3 5 9 2 2 4 8 (1) 0 2 4 6 (2) 2 2 2 6 (3) 0 0 4 4 (4) 0 4 0 4 (5) 4 4 4 4 (6) In this case, the sequence converged in 6 steps. It turns out that in all cases, the sequence converges very quickly. In fact, it can be shown that if all four integers are less than 2^n, then it will take no more than 3*n steps to converge! Given a, b, c and d, figure out just how quickly the sequence converges. Input There will be several test cases in the input. Each test case consists of four positive integers on a single line (1 ≤ a,b,c,d ≤ 2,000,000,000), with single spaces for separation. The input will end with a line with four 0s. Output For each test case, output a single integer on its own line, indicating the number of steps until convergence. Output no extra spaces, and do not separate answers with blank lines. Sample Input 1 3 5 9 4 3 2 1 1 1 1 1 0 0 0 0 Sample Output 6 4 0
Misaki's Kiss again
Problem Description After the Ferries Wheel, many friends hope to receive the Misaki's kiss again,so Misaki numbers them 1,2...N−1,N,if someone's number is M and satisfied the GCD(N,M) equals to N XOR M,he will be kissed again. Please help Misaki to find all M(1<=M<=N). Note that: GCD(a,b) means the greatest common divisor of a and b. A XOR B means A exclusive or B Input There are multiple test cases. For each testcase, contains a integets N(0<N<=1010) Output For each test case, first line output Case #X:, second line output k means the number of friends will get a kiss. third line contains k number mean the friends' number, sort them in ascending and separated by a space between two numbers Sample Input 3 5 15 Sample Output Case #1: 1 2 Case #2: 1 4 Case #3: 3 10 12 14
Contour Tracing 反跟踪问题
Problem Description In computer vision, objects of interest are often represented as regions of 1's in a binary image (bitmap). An important task in the identification of objects is to trace the contour (also called border and boundary) in an object. We assume that the bitmap does not contain any 1's on the borders. To trace the contour of a single object, we can use a procedure known as the Moore boundary tracking algorithm as follows: Scan from the top row to the bottom row, from left to right in each row, until an object pixel is found. Call this object pixel b0, and its west background neighbour c0. Examine the 8 neighbours of b0, starting at c0 and proceeding in clockwise direction. Let b1 denote the first neighbour object pixel encountered, and c1 be the background neighbour immediately preceeding b1. Store the locations of b0 and b1, and append b0 and b1 to the contour. Let b = b1 and c = c1 Let the 8 neighbours of b, starting at c and proceeding in a clockwise direction, be denoted as n1, n2, ..., n8. Find the first object neighbour nk in this sequence. Let b = nk, c = n(k-1). Append b to the contour. Repeat steps 4 and 5 until b = b0 and the next contour point found is b1. The last two points b0 and b1 are repeated and should not be appended to the contour again. The first steps of the algorithm is illustrated in the figure below (only the pixels on the boundary are labelled 1 in this bitmap): In this problem, you will be given a bitmap with at most 200 rows and 200 columns. The bitmap contains a number of objects. You are to determine the length of the contour for each object in the bitmap using the procedure above. In the bitmap, a pixel intensity of 0 represents the background, and a pixel intensity of 1 represents an object pixel. Two pixels with intensity 1 belong to the same object if there is a path from one pixel to another consisting of only 1's, and the path is allowed to follow in any of the 8 compass directions. The borders of the bitmap (first row, last row, first column, last column) contain only background pixels. Any object consisting of fewer than 5 pixels should be ignored as it is most likely noise. None of the objects in the bitmap has holes. Equivalently, there exists a path of background pixels following only the 4 main compass directions (N, S, E, W) for every pair of background pixels in the bitmap. Input The input consists of a number of cases. Each case starts with two positive integers on a line, indicating the number of rows (R) and the number of columns (C) in the bitmap. The bitmap is given in the following R lines each containing a string of 0's and 1's of length C. The input is terminated by a case starting with R = C = 0. The last case should not be processed. Output For each case, print the case number on its own line. In the next line, print the lengths of the contours of all objects found in the bitmap, sorted in ascending order. Separate the contour lengths by a single space on that line. If the bitmap has no object that have at least 5 pixels, output the line 'no objects found' instead. Sample Input 7 7 0000000 0011110 0111100 0011100 0111100 0111100 0000000 16 7 0000000 0011110 0111100 0011100 0111100 0111100 0000000 0011000 0100110 0000000 0001000 0010100 0010000 0111000 0111000 0000000 4 4 0000 0000 0010 0000 0 0 Sample Output Case 1 14 Case 2 8 12 14 Case 3 no objects found
Farey Sequence Again 的过程的编程
Problem Description The Farey sequence Fn for any positive integer n is the set of irreducible rational numbers a/b with 0<a<b<=n and (a, b) = 1 arranged in increasing order. Here (a, b) mean the greatest common divisor of a and b. For example: F2 = {1/2} F3 = {1/3, 1/2, 2/3} Given two positive integers N and K, with K less than N, you need to find out the K-th smallest element of the Farey sequence FN. Input The first line of input is the number of test case T, 1<=T<=1000. Then each test case contains two positive integers N and K. 1<=K<N<=10^9. Output For each test case output the Kth smallest element of the Farey sequence FN in a single line. Sample Input 3 2 1 100 68 101 69 Sample Output 1/2 2/83 1/42
Persistent Bits 实现
Problem Description WhatNext Software creates sequence generators that they hope will produce fairly random sequences of 16-bit unsigned integers in the range 0–65535. In general a sequence is specified by integers A, B, C, and S, where 1 ≤ A < 32768, 0 ≤ B < 65536, 2 ≤ C < 65536, and 0 ≤ S < C. S is the first element (the seed) of the sequence, and each later element is generated from the previous element. If X is an element of the sequence, then the next element is (A * X + B) % C where '%' is the remainder or modulus operation. Although every element of the sequence will be a 16-bit unsigned integer less than 65536, the intermediate result A * X + B may be larger, so calculations should be done with a 32-bit int rather than a 16-bit short to ensure accurate results. Some values of the parameters produce better sequences than others. The most embarrassing sequences to WhatNext Software are ones that never change one or more bits. A bit that never changes throughout the sequence is persistent. Ideally, a sequence will have no persistent bits. Your job is to test a sequence and determine which bits are persistent. For example, a particularly bad choice is A = 2, B = 5, C = 18, and S = 3. It produces the sequence 3, (2*3+5)%18 = 11, (2*11+5)%18 = 9, (2*9+5)%18 = 5, (2*5+5)%18 = 15, (2*15+5)%18 = 17, then (2*17+5)%18 = 3 again, and we're back at the beginning. So the sequence repeats the the same six values over and over: Decimal 16-Bit Binary 3 0000000000000011 11 0000000000001011 9 0000000000001001 5 0000000000000101 15 0000000000001111 17 0000000000010001 overall 00000000000????1 The last line of the table indicates which bit positions are always 0, always 1, or take on both values in the sequence. Note that 12 of the 16 bits are persistent. (Good random sequences will have no persistent bits, but the converse is not necessarily true. For example, the sequence defined by A = 1, B = 1, C = 64000, and S = 0 has no persistent bits, but it's also not random: it just counts from 0 to 63999 before repeating.) Note that a sequence does not need to return to the seed: with A = 2, B = 0, C = 16, and S = 2, the sequence goes 2, 4, 8, 0, 0, 0, .... Input There are from one to sixteen datasets followed by a line containing only 0. Each dataset is a line containing decimal integer values for A, B, C, and S, separated by single blanks. Output There is one line of output for each data set, each containing 16 characters, either '1', '0', or '?' for each of the 16 bits in order, with the most significant bit first, with '1' indicating the corresponding bit is always 1, '0' meaning the corresponding bit is always 0, and '?' indicating the bit takes on values of both 0 and 1 in the sequence. Sample Input 2 5 18 3 1 1 64000 0 2 0 16 2 256 85 32768 21845 1 4097 32776 248 0 Sample Output 00000000000????1 ???????????????? 000000000000???0 0101010101010101 0???000011111???
Extraordinarily Tired Students
Problem Description When a student is too tired, he can't help sleeping in class, even if his favorite teacher is right here in front of him. Imagine you have a class of extraordinarily tired students, how long do you have to wait, before all the students are listening to you and won't sleep any more? In order to complete this task, you need to understand how students behave. When a student is awaken, he struggles for a minutes listening to the teacher (after all, it's too bad to sleep all the time). After that, he counts the number of awaken and sleeping students (including himself). If there are strictly more sleeping students than awaken students, he sleeps for b minutes. Otherwise, he struggles for another a minutes, because he knew that when there is only very few sleeping students, there is a big chance for them to be punished! Note that a student counts the number of sleeping students only when he wants to sleep again. Now that you understand each student could be described by two integers a and b, the length of awaken and sleeping period. If there are always more sleeping students, these two periods continue again and again. We combine an awaken period with a sleeping period after it, and call the combined period an awaken-sleeping period. For example, a student with a=1 and b=4 has an awaken-sleeping period of awaken-sleeping-sleeping-sleeping-sleeping. In this problem, we need another parameter c (1 ≤ c ≤ a+b) to describe a student's initial condition: the initial position in his awaken-sleeping period. The 1st and 2nd position of the period discussed above are awaken and sleeping, respectively. Now we use a triple (a, b, c) to describe a student. Suppose there are three students (2, 4, 1), (1, 5, 2) and (1, 4, 3), all the students will be awaken at time 18. The details are shown in the table below. Write a program to calculate the first time when all the students are not sleeping. Input The input consists of several test cases. The first line of each case contains a single integer n (1 ≤ n ≤ 10), the number of students. This is followed by n lines, each describing a student. Each of these lines contains three integers a, b, c (1 ≤ a, b ≤ 5), described above. The last test case is followed by a single zero, which should not be processed. Output For each test case, print the case number and the first time all the students are awaken. If it'll never happen, output -1. Sample Input 3 2 4 1 1 5 2 1 4 3 3 1 2 1 1 2 2 1 2 3 0 Sample Output Case 1: 18 Case 2: -1
c语言编程 输入两个加数并计算结果，正确输出对，错误输出错，直道算对为止

Let's play UNO
Problem Description Uno is a famous card game played with a specially printed deck. It's very popular as a funny game in a party. A so-called "official rules" is presented at the Wikipedia, but there are a lot of different extended rules all over the world according to their specific needs. In this problem, you are required to obey our rules introduced below: The Uno deck consists of cards of 4 colors: red(R), green(G), blue(B), and yellow(Y). Each color has two kinds of cards, number cards and action cards. The ranks in number cards are 0-9. There are 3 "action" cards in each color, labeled "skip"(S), "draw two"(D), and "reverse"(R). The functions of the actions will be described afterwards. For each color, there are two copies of each positive number card and action card, but only one zero card, producing 25 cards in total. Besides, there are also special black action cards called "wild cards", "wild"(WC) and "wild draw four"(WF). There are four "wild" and "wild draw four" cards each. Hence, there are 108 cards in total. In this problem, a card is marked with an ID of two characters length, the first is the color (R, G, B, Y, W) while the second is the rank (0-9, S, D, R, C, F). For example, the ID of red 2 is R2, the yellow reverse is YR, the wild cards are WC and WF. Supposed there are n players numbered from 1 to n clockwise. Before playing, players take turns(in the order of 1, 2, ... n) to pick seven successive cards from the stock. The top card of the remaining stock is exposed to start the game, treated as if player 1 dropped that card. The exposed card will never be WC or WF in this problem. Then the game begins clockwise (next player is 2), or counter-clockwise (next player is n) if the top exposed card is a reverse. At each turn, a player may drop a card from their hand that matches the color or rank of the top exposed card (e.g., if the top card is R3, you can drop R5 or G3; if the top card is RD, you can drop R3 or GD) or play a WC. What's more, if the player has a WF and no other legal cards to drop, he can drop the WF. Then the card dropped just now becomes the top exposed card. If a player has no legal cards, he must draw the top card of the stock and place it in his hand. After dropping a single card or drawing, the next player clockwise takes a turn, or counter-clockwise when the reverse is in effect. When a player drops down to only one card, that player is required to say "uno" to warn other players. The game ends when a player drops all his/her cards, or the stock is emptied but the current player has to draw a card. If the last card is an action card, the special effect still occurs. When the game ends, all players count the number of points pertaining to the values of the cards in their hands. Number cards worth the face value on them, colored special cards worth twenty, and wilds worth fifty, e.g., R2 worth 2, G0 worth 0, BD and YS worth 20, WC and WF worth 50. The descriptions of the action cards: Now here comes the problem. There are N people playing Uno under the rules mentioned above. Given the sequence of the 108 cards of the stock, you are asked to simulate a Uno game. At each turn, the player will always drop a card if permitted. If there are more than one choices, the player will drop the card with the largest point. If still a tie, he will choose the one whose ID is the smallest alphabetical order. When a player drops WC or WF, he has to name a color. The first time he will name red, the second time he will name green, the third time blue, the fourth time yellow, the fifth time red again, and so on. When the game ends, you should output the final score of each player, and we also want to know how many times each player calls "Uno". Input The first line of the input file contains a single number: the number of test cases to follow. Each test case has two lines: The first line contains the number of players N , with 2<=N<=10. The second line contains 108 IDs of the Uno cards, separated by one space. Each ID is two characters long as introduced in the description above. Output For each test case, output two lines: The first line are N integers, the ith integer is the final score of player i. The second lines are also N integers, the ith integer shows how many times player i calls "Uno". Sample Input 1 2 R9 RD RD RS RS RR RR B0 B1 B1 B2 B2 B3 B3 G0 GD GD GS GS GR GR G9 G9 G8 G8 G7 G7 G6 G6 G5 G5 G4 G4 G3 G3 G2 G2 G1 G1 Y0 Y9 Y9 Y8 Y8 Y7 Y7 Y6 Y6 Y5 Y5 Y4 Y4 Y3 Y3 Y2 Y2 Y1 Y1 YD YD YS YS YR YR R9 R8 R8 R7 R7 R6 R6 R5 R5 R4 R4 R3 R3 R2 R2 R1 R1 R0 B4 B4 B5 B5 B6 B6 B7 B7 B8 B8 B9 B9 BD BD BS BS BR BR WC WC WC WC WF WF WF WF Sample Output 249 0 0 1
Cutting trees 设计的问题
Problem Description A rooted graph is an indirected graph with every edge attached by some path to a special vertex called the root or the ground. The ground is denoted in the below figures that follow by a dotted line. A bamboo stalk with n segments is a linear graph of n edges with the bottom of the n edges rooted to the ground. A move consists of hacking away one of the segments, and removing that segment and all segments above it no longer connectd to the ground. Two players alternate moves and the last player to move wins. A single bamboo stalk of n segments can be moved into a bamboo stalk of any smaller number of segments from n-1 to 0. So a single bamboo stalk of n segments is equivalent to a nim pile of n chips. As you known, the player who moves first can win the the game with only one bamboo stalk. So many people always play the game with several bamboo stalks. One example is as below: Playing a sum of games of bamboo stalks is thus equivalent to playing a nim game that with several piles. A move consisits of selecting a bamboo stalk containg n segments and hacking away one of the segments in the selected bamboo stalk. I think the nim game is easy for you, the smart ACMers. So, today, we play a game named "cutting trees". A "rooted tree" is a graph with a distinguished vertex called the root, with the property that from every vertex there is unique path(that doesn't repeat edges) to the root. Essentially this means there are no cycles. Of course, in the game "cutting trees", there are several trees.Again, a move consisits of selecting a tree and hacking away any segment and removing segment and anything not connected to the ground. The player who cuts the last segment wins the game. Input Standard input will contain multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each case begins with a N(1<=N<=1000), the number of trees in the game.A tree is decribed by a number m, the nodes of the tree and R(0<=R<=m-1), the root of the tree. Then m-1 lines follow, each line containg two positive integers A,B∈[0,m-1], means that there is a edge between A and B. In the game, the first player always moves first. Output Results should be directed to standard output. For each case, if the first player wins, ouput "The first player wins", or else, output "The second player wins",in a single line. Sample Input 1 1 4 0 0 1 1 2 1 3 Sample Output The first player wins

Java学习的正确打开方式

linux系列之常用运维命令整理笔录

Python十大装B语法
Python 是一种代表简单思想的语言，其语法相对简单，很容易上手。不过，如果就此小视 Python 语法的精妙和深邃，那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点，并附上详细的实例代码。如能在实战中融会贯通、灵活使用，必将使代码更为精炼、高效，同时也会极大提升代码B格，使之看上去更老练，读起来更优雅。

2019年11月中国大陆编程语言排行榜
2019年11月2日，我统计了某招聘网站，获得有效程序员招聘数据9万条。针对招聘信息，提取编程语言关键字，并统计如下： 编程语言比例 rank pl_ percentage 1 java 33.62% 2 cpp 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7 p...

JDK12 Collectors.teeing 你真的需要了解一下

SQL-小白最佳入门sql查询一

【图解经典算法题】如何用一行代码解决约瑟夫环问题

“狗屁不通文章生成器”登顶GitHub热榜，分分钟写出万字形式主义大作

GitHub标星近1万：只需5秒音源，这个网络就能实时“克隆”你的声音

《程序人生》系列-这个程序员只用了20行代码就拿了冠军

11月8日，由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办，科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。 　　区块链技术被认为是继蒸汽机、电力、互联网之后，下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力，电力解决了人类基本的生活需求，互联网彻底改变了信息传递的方式，区块链作为构造信任的技术有重要的价值。 　　1...

【技巧总结】位运算装逼指南

【管理系统课程设计】美少女手把手教你后台管理
【文章后台管理系统】URL设计与建模分析+项目源码+运行界面 栏目管理、文章列表、用户管理、角色管理、权限管理模块（文章最后附有源码） 1. 这是一个什么系统? 1.1 学习后台管理系统的原因 随着时代的变迁，现如今各大云服务平台横空出世，市面上有许多如学生信息系统、图书阅读系统、停车场管理系统等的管理系统，而本人家里就有人在用烟草销售系统，直接在网上完成挑选、购买与提交收货点，方便又快捷。 试想，若没有烟草销售系统，本人家人想要购买烟草，还要独自前往药...
4G EPS 第四代移动通信系统