Problem Description
Falling Stocks. Bankrupted companies. Banks with no Cash. Seems like the best time to invest: ``Think I'll buy me a football team!"

No seriously, I think I have the solution to at least the problem of cash in banks. Banks nowadays are all owing each other great amounts of money and no bank has enough cash to pay other banks' debts even though, on paper at least, they should have enough money to do so. Take for example the inter-bank loans shown in figure (a). The graph shows the amounts owed between four banks (A ...D). For example, A owes B 50M while, at the same time, B owes A 150M. (It is quite common for two banks to owe each other at the same time.) A total amount of 380M in cash is needed to settle all debts between the banks.

In an attempt to decrease the need for cash, and after studying the example carefully, I concluded that there's a lot of cash being transferred unnecessarily. Take a look:

1. C owes D the same amount as D owes A, so we can say that C owes A an amount of 30M and get D out of the picture.
2. But since A already owes C 100M, we can say that A owes C an amount of 70M.
3. Similarly, B owes A 100M only, (since A already owes B 50M.) This reduces the above graph to the one shown in figure (b) which reduces the needed cash amount to 190M (A reduction of 200M, or 53%.)
4. I can still do better. Rather than B paying A 100M and A paying 70M to C, B can pay 70M (out of A's 100M) directly to C. This reduces the graph to the one shown in figure (c). Banks can settle all their debts with only 120M in cash. A total reduction of 260M or 68%. Amazing!

I have data about inter-bank debts but I can't seem to be able to process it to obtain the minimum amount of cash needed to settle all the debts. Could you please write a program to do that?

Input
Your program will be tested on one or more test cases. Each test case is specified on N + 1 lines where N < 1, 000 is the number of banks and is specified on the first line. The remaining N lines specifies the inter-bank debts using an N×N adjacency matrix (with zero diagonal) specified in row-major order. The ith row specifies the amounts owed by the ith bank. Amounts are separated by one or more spaces. All amounts are less than 1000. The last line of the input file has a single 0.

Output
For each test case, print the result using the following format:

k . B A

where k is the test case number (starting at 1,) is a space character, B is the amount of cash needed before reduction and A is the amount of cash after reduction.

Sample Input
4
0 50 100 0
150 0 20 0
0 0 0 30
30 0 0 0
0

Sample Output
1. 380 120

Think I’ll Buy Me a Football Team 球队问题
Problem Description Falling Stocks. Bankrupted companies. Banks with no Cash. Seems like the best time to invest: ``Think I'll buy me a football team!" No seriously, I think I have the solution to at least the problem of cash in banks. Banks nowadays are all owing each other great amounts of money and no bank has enough cash to pay other banks' debts even though, on paper at least, they should have enough money to do so. Take for example the inter-bank loans shown in figure (a). The graph shows the amounts owed between four banks (A ...D). For example, A owes B 50M while, at the same time, B owes A 150M. (It is quite common for two banks to owe each other at the same time.) A total amount of 380M in cash is needed to settle all debts between the banks. In an attempt to decrease the need for cash, and after studying the example carefully, I concluded that there's a lot of cash being transferred unnecessarily. Take a look: 1. C owes D the same amount as D owes A, so we can say that C owes A an amount of 30M and get D out of the picture. 2. But since A already owes C 100M, we can say that A owes C an amount of 70M. 3. Similarly, B owes A 100M only, (since A already owes B 50M.) This reduces the above graph to the one shown in figure (b) which reduces the needed cash amount to 190M (A reduction of 200M, or 53%.) 4. I can still do better. Rather than B paying A 100M and A paying 70M to C, B can pay 70M (out of A's 100M) directly to C. This reduces the graph to the one shown in figure (c). Banks can settle all their debts with only 120M in cash. A total reduction of 260M or 68%. Amazing! I have data about inter-bank debts but I can't seem to be able to process it to obtain the minimum amount of cash needed to settle all the debts. Could you please write a program to do that? Input Your program will be tested on one or more test cases. Each test case is specified on N + 1 lines where N < 1, 000 is the number of banks and is specified on the first line. The remaining N lines specifies the inter-bank debts using an N×N adjacency matrix (with zero diagonal) specified in row-major order. The ith row specifies the amounts owed by the ith bank. Amounts are separated by one or more spaces. All amounts are less than 1000. The last line of the input file has a single 0. Output For each test case, print the result using the following format: k . B A where k is the test case number (starting at 1,) is a space character, B is the amount of cash needed before reduction and A is the amount of cash after reduction. Sample Input 4 0 50 100 0 150 0 20 0 0 0 0 30 30 0 0 0 0 Sample Output 1. 380 120
Think I’ll Buy Me a Football Team
Problem Description Falling Stocks. Bankrupted companies. Banks with no Cash. Seems like the best time to invest: ``Think I'll buy me a football team!" No seriously, I think I have the solution to at least the problem of cash in banks. Banks nowadays are all owing each other great amounts of money and no bank has enough cash to pay other banks' debts even though, on paper at least, they should have enough money to do so. Take for example the inter-bank loans shown in figure (a). The graph shows the amounts owed between four banks (A ...D). For example, A owes B 50M while, at the same time, B owes A 150M. (It is quite common for two banks to owe each other at the same time.) A total amount of 380M in cash is needed to settle all debts between the banks. In an attempt to decrease the need for cash, and after studying the example carefully, I concluded that there's a lot of cash being transferred unnecessarily. Take a look: 1. C owes D the same amount as D owes A, so we can say that C owes A an amount of 30M and get D out of the picture. 2. But since A already owes C 100M, we can say that A owes C an amount of 70M. 3. Similarly, B owes A 100M only, (since A already owes B 50M.) This reduces the above graph to the one shown in figure (b) which reduces the needed cash amount to 190M (A reduction of 200M, or 53%.) 4. I can still do better. Rather than B paying A 100M and A paying 70M to C, B can pay 70M (out of A's 100M) directly to C. This reduces the graph to the one shown in figure (c). Banks can settle all their debts with only 120M in cash. A total reduction of 260M or 68%. Amazing! I have data about inter-bank debts but I can't seem to be able to process it to obtain the minimum amount of cash needed to settle all the debts. Could you please write a program to do that? Input Your program will be tested on one or more test cases. Each test case is specified on N + 1 lines where N < 1, 000 is the number of banks and is specified on the first line. The remaining N lines specifies the inter-bank debts using an N×N adjacency matrix (with zero diagonal) specified in row-major order. The ith row specifies the amounts owed by the ith bank. Amounts are separated by one or more spaces. All amounts are less than 1000. The last line of the input file has a single 0. Output For each test case, print the result using the following format: k . B A where k is the test case number (starting at 1,) is a space character, B is the amount of cash needed before reduction and A is the amount of cash after reduction. Sample Input 4 0 50 100 0 150 0 20 0 0 0 0 30 30 0 0 0 0 Sample Output 1. 380 120
Think I’ll Buy Me a Football Team 状态的问题
Problem Description Falling Stocks. Bankrupted companies. Banks with no Cash. Seems like the best time to invest: ``Think I'll buy me a football team!" No seriously, I think I have the solution to at least the problem of cash in banks. Banks nowadays are all owing each other great amounts of money and no bank has enough cash to pay other banks' debts even though, on paper at least, they should have enough money to do so. Take for example the inter-bank loans shown in figure (a). The graph shows the amounts owed between four banks (A ...D). For example, A owes B 50M while, at the same time, B owes A 150M. (It is quite common for two banks to owe each other at the same time.) A total amount of 380M in cash is needed to settle all debts between the banks. In an attempt to decrease the need for cash, and after studying the example carefully, I concluded that there's a lot of cash being transferred unnecessarily. Take a look: 1. C owes D the same amount as D owes A, so we can say that C owes A an amount of 30M and get D out of the picture. 2. But since A already owes C 100M, we can say that A owes C an amount of 70M. 3. Similarly, B owes A 100M only, (since A already owes B 50M.) This reduces the above graph to the one shown in figure (b) which reduces the needed cash amount to 190M (A reduction of 200M, or 53%.) 4. I can still do better. Rather than B paying A 100M and A paying 70M to C, B can pay 70M (out of A's 100M) directly to C. This reduces the graph to the one shown in figure (c). Banks can settle all their debts with only 120M in cash. A total reduction of 260M or 68%. Amazing! I have data about inter-bank debts but I can't seem to be able to process it to obtain the minimum amount of cash needed to settle all the debts. Could you please write a program to do that? Input Your program will be tested on one or more test cases. Each test case is specified on N + 1 lines where N < 1, 000 is the number of banks and is specified on the first line. The remaining N lines specifies the inter-bank debts using an N×N adjacency matrix (with zero diagonal) specified in row-major order. The ith row specifies the amounts owed by the ith bank. Amounts are separated by one or more spaces. All amounts are less than 1000. The last line of the input file has a single 0. Output For each test case, print the result using the following format: k . B A where k is the test case number (starting at 1,) is a space character, B is the amount of cash needed before reduction and A is the amount of cash after reduction. Sample Input 4 0 50 100 0 150 0 20 0 0 0 0 30 30 0 0 0 0 Sample Output 1. 380 120
Think I’ll Buy Me a Football Team
Problem Description Falling Stocks. Bankrupted companies. Banks with no Cash. Seems like the best time to invest: ``Think I'll buy me a football team!" No seriously, I think I have the solution to at least the problem of cash in banks. Banks nowadays are all owing each other great amounts of money and no bank has enough cash to pay other banks' debts even though, on paper at least, they should have enough money to do so. Take for example the inter-bank loans shown in figure (a). The graph shows the amounts owed between four banks (A ...D). For example, A owes B 50M while, at the same time, B owes A 150M. (It is quite common for two banks to owe each other at the same time.) A total amount of 380M in cash is needed to settle all debts between the banks. In an attempt to decrease the need for cash, and after studying the example carefully, I concluded that there's a lot of cash being transferred unnecessarily. Take a look: 1. C owes D the same amount as D owes A, so we can say that C owes A an amount of 30M and get D out of the picture. 2. But since A already owes C 100M, we can say that A owes C an amount of 70M. 3. Similarly, B owes A 100M only, (since A already owes B 50M.) This reduces the above graph to the one shown in figure (b) which reduces the needed cash amount to 190M (A reduction of 200M, or 53%.) 4. I can still do better. Rather than B paying A 100M and A paying 70M to C, B can pay 70M (out of A's 100M) directly to C. This reduces the graph to the one shown in figure (c). Banks can settle all their debts with only 120M in cash. A total reduction of 260M or 68%. Amazing! I have data about inter-bank debts but I can't seem to be able to process it to obtain the minimum amount of cash needed to settle all the debts. Could you please write a program to do that? Input Your program will be tested on one or more test cases. Each test case is specified on N + 1 lines where N < 1, 000 is the number of banks and is specified on the first line. The remaining N lines specifies the inter-bank debts using an N×N adjacency matrix (with zero diagonal) specified in row-major order. The ith row specifies the amounts owed by the ith bank. Amounts are separated by one or more spaces. All amounts are less than 1000. The last line of the input file has a single 0. Output For each test case, print the result using the following format: k . B A where k is the test case number (starting at 1,) is a space character, B is the amount of cash needed before reduction and A is the amount of cash after reduction. Sample Input 4 0 50 100 0 150 0 20 0 0 0 0 30 30 0 0 0 0 Sample Output 1. 380 120
Think I’ll Buy Me a Football Team 采用程序的设计
Problem Description Falling Stocks. Bankrupted companies. Banks with no Cash. Seems like the best time to invest: ``Think I'll buy me a football team!" No seriously, I think I have the solution to at least the problem of cash in banks. Banks nowadays are all owing each other great amounts of money and no bank has enough cash to pay other banks' debts even though, on paper at least, they should have enough money to do so. Take for example the inter-bank loans shown in figure (a). The graph shows the amounts owed between four banks (A ...D). For example, A owes B 50M while, at the same time, B owes A 150M. (It is quite common for two banks to owe each other at the same time.) A total amount of 380M in cash is needed to settle all debts between the banks. In an attempt to decrease the need for cash, and after studying the example carefully, I concluded that there's a lot of cash being transferred unnecessarily. Take a look: 1. C owes D the same amount as D owes A, so we can say that C owes A an amount of 30M and get D out of the picture. 2. But since A already owes C 100M, we can say that A owes C an amount of 70M. 3. Similarly, B owes A 100M only, (since A already owes B 50M.) This reduces the above graph to the one shown in figure (b) which reduces the needed cash amount to 190M (A reduction of 200M, or 53%.) 4. I can still do better. Rather than B paying A 100M and A paying 70M to C, B can pay 70M (out of A's 100M) directly to C. This reduces the graph to the one shown in figure (c). Banks can settle all their debts with only 120M in cash. A total reduction of 260M or 68%. Amazing! I have data about inter-bank debts but I can't seem to be able to process it to obtain the minimum amount of cash needed to settle all the debts. Could you please write a program to do that? Input Your program will be tested on one or more test cases. Each test case is specified on N + 1 lines where N < 1, 000 is the number of banks and is specified on the first line. The remaining N lines specifies the inter-bank debts using an N×N adjacency matrix (with zero diagonal) specified in row-major order. The ith row specifies the amounts owed by the ith bank. Amounts are separated by one or more spaces. All amounts are less than 1000. The last line of the input file has a single 0. Output For each test case, print the result using the following format: k . B A where k is the test case number (starting at 1,) is a space character, B is the amount of cash needed before reduction and A is the amount of cash after reduction. Sample Input 4 0 50 100 0 150 0 20 0 0 0 0 30 30 0 0 0 0 Sample Output 1. 380 120
C++足球队的问题，如何使用搜索算法实现，图在下面
Problem Description Falling Stocks. Bankrupted companies. Banks with no Cash. Seems like the best time to invest: ``Think I'll buy me a football team!" No seriously, I think I have the solution to at least the problem of cash in banks. Banks nowadays are all owing each other great amounts of money and no bank has enough cash to pay other banks' debts even though, on paper at least, they should have enough money to do so. Take for example the inter-bank loans shown in figure (a). The graph shows the amounts owed between four banks (A ...D). For example, A owes B 50M while, at the same time, B owes A 150M. (It is quite common for two banks to owe each other at the same time.) A total amount of 380M in cash is needed to settle all debts between the banks. ![](http://acm.hdu.edu.cn/data/images/con208-1007-1.JPG) In an attempt to decrease the need for cash, and after studying the example carefully, I concluded that there's a lot of cash being transferred unnecessarily. Take a look: 1. C owes D the same amount as D owes A, so we can say that C owes A an amount of 30M and get D out of the picture. 2. But since A already owes C 100M, we can say that A owes C an amount of 70M. 3. Similarly, B owes A 100M only, (since A already owes B 50M.) This reduces the above graph to the one shown in figure (b) which reduces the needed cash amount to 190M (A reduction of 200M, or 53%.) 4. I can still do better. Rather than B paying A 100M and A paying 70M to C, B can pay 70M (out of A's 100M) directly to C. This reduces the graph to the one shown in figure (c). Banks can settle all their debts with only 120M in cash. A total reduction of 260M or 68%. Amazing! I have data about inter-bank debts but I can't seem to be able to process it to obtain the minimum amount of cash needed to settle all the debts. Could you please write a program to do that? Input Your program will be tested on one or more test cases. Each test case is specified on N + 1 lines where N < 1, 000 is the number of banks and is specified on the first line. The remaining N lines specifies the inter-bank debts using an N×N adjacency matrix (with zero diagonal) specified in row-major order. The ith row specifies the amounts owed by the ith bank. Amounts are separated by one or more spaces. All amounts are less than 1000. The last line of the input file has a single 0. Output For each test case, print the result using the following format: k . B A where k is the test case number (starting at 1,) is a space character, B is the amount of cash needed before reduction and A is the amount of cash after reduction. Sample Input 4 0 50 100 0 150 0 20 0 0 0 0 30 30 0 0 0 0 Sample Output 1. 380 120
I Think I Need a Houseboat 的实现
Problem Description Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square miles each year, due to erosion caused by the Mississippi River. Since Fred is hoping to live in this house the rest of his life, he needs to know if his land is going to be lost to erosion. After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the X axis. Locations below the X axis are in the water. The semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.) Input The first line of input will be a positive integer indicating how many data sets will be included (N). Each of the next N lines will contain the X and Y Cartesian coordinates of the land Fred is considering. These will be floating point numbers measured in miles. The Y coordinate will be non-negative. (0,0) will not be given. Output For each data set, a single line of output should appear. This line should take the form of: “Property N: This property will begin eroding in year Z.” Where N is the data set (counting from 1), and Z is the first year (start from 1) this property will be within the semicircle AT THE END OF YEAR Z. Z must be an integer. After the last data set, this should print out “END OF OUTPUT.” Notes: 1. No property will appear exactly on the semicircle boundary: it will either be inside or outside. 2. This problem will be judged automatically. Your answer must match exactly, including the capitalization, punctuation, and white-space. This includes the periods at the ends of the lines. 3. All locations are given in miles. Sample Input 2 1.0 1.0 25.0 0.0 Sample Output Property 1: This property will begin eroding in year 1. Property 2: This property will begin eroding in year 20. END OF OUTPUT.
Find Black Hand 的问题
Problem Description I like playing game with my friends, although sometimes look pretty naive. Today I invent a new game called find black hand. The game is not about catching bad people but playing on a string. Now I generate a string S and several short ones s[i], and I define three kinds of operations. 1. Delete: remove the ith character. 2. Insert: in any position, insert a character if you like. 3. Change: change the ith character into another character if you like. For each short string s[i], we define a function f(i). After several operations on S, we can find a substring of S which is the same to s[i]. And f(i) is the minimal number of operations to achieve. It looks so native that I think every one of you can solve f(i) perfectly. So I join the string S from end to end, and f(i) changes nothing. So the string "bb" is also a substring of string "baaab". The "black hand" is the short string s[i] whose f(i) is minimal. Now it's your time to find the black hand. Input There are multiple test cases. The first line contains a non-empty string S whose length is not more than 100,000. The next line contains an integer N (1 <= N <= 10) indicating the number of the short string. Each of the next N lines contains a short non-empty string whose length is not more than 10. All strings in the input would not have blank and all characters are lower case. Output For each test case, output a string first indicating the "black hand", and then output an integer indicating the minimal number of the operation. If there are more than one "black hand", please output the smallest one in lexicographical order. Sample Input aaabbbb 2 alice bob Sample Output bob 1
Yuanfang, What Do You Think? 表达式的计算
Problem Description Factoring a polynomial is always a hard and important issue in mathematics teaching in middle schools. Teacher Liu loves teaching this issue very much, but his students are not good at it. Yuanfang is the best student in Teacher Liu's class. Every time when Teacher Liu comes up with a hard problem and it seems no student can solve it, Liu always says: "Yuanfang , what do you think?"。 This week, Teacher Liu began to teach how to factor a polynomial. On Monday, Teacher Liu said : "Let's factor x2-1 ... Yuanfang, what do you think?" On Tuesday, Teacher Liu said : "Let's factor x3-1 ... Yuanfang, what do you think?" On Wednesday, Teacher Liu said : "Let's factor x4-1 ... Yuanfang, what do you think?" ….. On Friday, Yuanfang got crazy. She wanted to solve this problem permanently. So she came to you, the only programmer she knows, for help. You should write a program to factor the polynomial xn-1. In other words, represent the polynomial xn-1 by a product of irreducible polynomials in which coefficients are all integers. Input There are several test cases. Every case is an integer n in a line (n≤1100) meaning that you should factor the polynomial xn-1. Input ends with n=0. Output We print polynomials like this: 1.x2 to x^2; 2.x3-1 to x^3-1; 3.x6-2x4+1 to x^6-2x^4+1. For each test case, you should print the result polynomials in a certain order. To sort the polynomials, we compare the coefficients of them from high-degree to low-degree. The coefficient with a smaller absolute value has a smaller order. When absolute values are the same, negative coefficient has a smaller order. Please print the result polynomials from small order to large order. In the result, put every factor polynomial between a pair of parentheses(Except that the result is just x-1 as shown in sample). Every factor polynomial must satisfy the following conditions: 1.It can't be factored any more. 2.All the terms of the same degree must be combined. 3.No term's coefficient is 0. 4.The terms appear in the descending order by degree. 5.All coefficients are integers. Sample Input 1 2 3 4 5 6 0 Sample Output x-1 (x-1)(x+1) (x-1)(x^2+x+1) (x-1)(x+1)(x^2+1) (x-1)(x^4+x^3+x^2+x+1) (x-1)(x+1)(x^2-x+1)(x^2+x+1)
Sunday Drive 驾驶的问题
Problem Description After wracking your brains at a programing contest on Saturday, you’d like to relax by taking a leisurely Sunday drive. But, gasoline is so expensive nowadays! Maybe, by creatively changing lanes, you can minimize the distance you travel and save some money! You will be given a description of several sections of a highway. All sections will have the same number of lanes. Think of your car as a point mass, moving down the center of the lane. Each lane will be 10 feet wide. There are two kinds of highway sections: curved and straight. You can only change lanes on straight sections, and it takes a minimum of 100 feet of the straight section to move over one lane. You can take longer than that, of course, if you choose. All curve sections will make 90 degree turns. You cannot change lanes on a curve section. In addition, you must be driving along the exact middle of a lane during a turn. So during a turn your position will be 5 feet, or 15 feet, or 25 feet from the edge, etc. Given a description of a highway, compute the minimum total distance required travel the entire highway, including curves and lane changes. You can start, and end, in any lane you choose. Assume that your car is a point mass in the center of the lane. The highway may cross over/under itself, but the changes in elevation are miniscule, so you shouldn’t worry about their impact on your distance traveled. In order to be used to cross 2 lanes, this straight section must be at least 200 feet long. Input There will be several test cases in the input. Each test case will begin with two integers N M Where N (1 ≤ N ≤ 1,000) is the number of segments, and M (2 ≤ M ≤ 10) is the number of lanes. On each of the next N lines will be a description of a segment, consisting of a letter and a number, with a single space between them: T K The letter T is one of S, L, or R (always capital). This indicates the type of the section: a straight section (S), a left curve (L) or a right curve (R). If the section is a straight section, then the number K (10 ≤ K ≤ 10,000) is simply its length, in feet. If the section is a right or left curve, then the number K (10 ≤ K ≤ 10,000) is the radius of the inside edge of the highway, again in feet. There will never be consecutive straight sections in the input, but multiple consecutive turns are possible. The input will end with a line with two 0s. Output For each test case, print a single number on its own line, indicating the minimum distance (in feet) required to drive the entire highway. The number should be printed with exactly two decimal places, rounded. Output no extra spaces, and do not separate answers with blank lines. Sample Input 3 3 R 100 S 1000 L 100 9 5 S 2500 L 500 S 2000 L 500 S 5000 L 500 S 2000 L 500 S 2500 5 4 L 100 L 100 L 100 L 100 L 100 0 0 Sample Output 1330.07 17173.01 824.67
I Think I Need a Houseboat 怎么来实现的
Description Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square miles each year, due to erosion caused by the Mississippi River. Since Fred is hoping to live in this house the rest of his life, he needs to know if his land is going to be lost to erosion. After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the X axis. Locations below the X axis are in the water. The semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.) Input The first line of input will be a positive integer indicating how many data sets will be included (N). Each of the next N lines will contain the X and Y Cartesian coordinates of the land Fred is considering. These will be floating point numbers measured in miles. The Y coordinate will be non-negative. (0,0) will not be given. Output For each data set, a single line of output should appear. This line should take the form of: “Property N: This property will begin eroding in year Z.” Where N is the data set (counting from 1), and Z is the first year (start from 1) this property will be within the semicircle AT THE END OF YEAR Z. Z must be an integer. After the last data set, this should print out “END OF OUTPUT.” Sample Input 2 1.0 1.0 25.0 0.0 Sample Output Property 1: This property will begin eroding in year 1. Property 2: This property will begin eroding in year 20. END OF OUTPUT.
Sunday Drive 的问题
Problem Description After wracking your brains at a programing contest on Saturday, you’d like to relax by taking a leisurely Sunday drive. But, gasoline is so expensive nowadays! Maybe, by creatively changing lanes, you can minimize the distance you travel and save some money! You will be given a description of several sections of a highway. All sections will have the same number of lanes. Think of your car as a point mass, moving down the center of the lane. Each lane will be 10 feet wide. There are two kinds of highway sections: curved and straight. You can only change lanes on straight sections, and it takes a minimum of 100 feet of the straight section to move over one lane. You can take longer than that, of course, if you choose. All curve sections will make 90 degree turns. You cannot change lanes on a curve section. In addition, you must be driving along the exact middle of a lane during a turn. So during a turn your position will be 5 feet, or 15 feet, or 25 feet from the edge, etc. Given a description of a highway, compute the minimum total distance required travel the entire highway, including curves and lane changes. You can start, and end, in any lane you choose. Assume that your car is a point mass in the center of the lane. The highway may cross over/under itself, but the changes in elevation are miniscule, so you shouldn’t worry about their impact on your distance traveled. In order to be used to cross 2 lanes, this straight section must be at least 200 feet long. Input There will be several test cases in the input. Each test case will begin with two integers N M Where N (1 ≤ N ≤ 1,000) is the number of segments, and M (2 ≤ M ≤ 10) is the number of lanes. On each of the next N lines will be a description of a segment, consisting of a letter and a number, with a single space between them: T K The letter T is one of S, L, or R (always capital). This indicates the type of the section: a straight section (S), a left curve (L) or a right curve (R). If the section is a straight section, then the number K (10 ≤ K ≤ 10,000) is simply its length, in feet. If the section is a right or left curve, then the number K (10 ≤ K ≤ 10,000) is the radius of the inside edge of the highway, again in feet. There will never be consecutive straight sections in the input, but multiple consecutive turns are possible. The input will end with a line with two 0s. Output For each test case, print a single number on its own line, indicating the minimum distance (in feet) required to drive the entire highway. The number should be printed with exactly two decimal places, rounded. Output no extra spaces, and do not separate answers with blank lines. Sample Input 3 3 R 100 S 1000 L 100 9 5 S 2500 L 500 S 2000 L 500 S 5000 L 500 S 2000 L 500 S 2500 5 4 L 100 L 100 L 100 L 100 L 100 0 0 Sample Output 1330.07 17173.01 824.67
Throw the Stones 丢石头的问题
Problem Description 　　Remember our childhood? A few naked children throw stones standing on the same position, the one throws farther win the game. Aha, of course, there are some naughty boys who care more about whether they can urinate father. 　　You believe it or not, anyway, I believed. Nowadays, some of the children are smarter than we were, while others may be more naughty. 　　A week ago, I saw several children throw stones. In fact, they are more clever than we were, since the game they played, apparently, is more complex than we did. Maybe you have different points of view, however, you’d better learn about the rules of the game before expressing your views. A group of children take turns to throw stones standing on the same position. After some child throw a stone, the children will draw a convex polyhedron with smallest volume together to enclose all the stones thrown by them. You may assume that the stone is so small as to be abstracted as a point in three-dimensional space. Naively, the children regard the space enclosed by the convex polyhedron as territory under their control. After a child throw his stone, the score he obtains equals the incremental of the volume of their territory. Unfortunately, the first three child’s score will always be zero. At last, the child with the highest score will win the game, and known as the "King". 　　I think you have accepted my opinion already, for the rules of their throwing stones game are really complicated. But, you also don’t need to be frustrated for it. Now, in order to show you are smarter, maybe you can write a program to help the children point out their "King". Input 　　Input consists of a number of cases. The data of each case appears on a number of input lines, the first of which contains an integer N. The following N lines contain three number (xi, yi, zi) indicating coordinates of the stone thrown by the i-th child. Note: 1 <= N <= 10^4, 1 <= i <= N, -10^4 <= xi , yi , zi <= 10^4. Output 　　For each test case, you should output two lines. The first line is "Case #K:", K means the number of the test case. The second line is "i v", i means index of the "King" and v means the score of the "King". If there are more than one "King", output the one throws stone earlier than others. 　　Please round the result to 2 digits after decimal point if necessary. Sample Input 4 1 0 0 1 1 0 0 1 0 0 0 1 5 1 0 0 1 1 0 0 1 0 0 0 0 0 0 1 Sample Output Case #1： 4 0.17 Case #2： 5 0.33

Problem Description Most of us at one time or another have used a circular combination lock (think back to those glorious days in high school and your gym locker). Most combination locks consist of a dial with the numbers 0 through n-1 printed on it in clockwise order. The dial can be turned either clockwise or counterclockwise, bringing one of the numbers to the top of the dial (if 0 is at the top of the dial, a turn of 1 in the counterclockwise direction would bring 1 to the top). Each lock has a three number code (x, y, z) and can only be opened after the following series of steps: 1. The lock dial must first be spun clockwise at least one full rotation, ending with the number x at the top (with no intervening counterclockwise turns). Note this could be accomplished with consecutive clockwise turns. 2. The lock must be turned counterclockwise until the number y appears at the top for the second time. Note this could be accomplished with consecutive counterclockwise turns (but no intervening clockwise turns). 3. The lock must then be turned clockwise until the number z appears on top, without going more than one full rotation. Note this could be accomplished with consecutive clockwise turns (but no intervening counterclockwise turns). Any rotation after this last step will cause the lock to be closed again. For this problem, you will be given a lock and a series of turns and you must determine at the end whether or not the lock is open. You should assume prior to the first turn that the lock has just been closed, and the dial spun counterclockwise until 0 is on top. Input Input will consist of multiple test cases. The first line of each test case will contain four integers n x y z, indicating the number of digits on the lock’s dial and the three-number combination (x, y and z will all be different and n <= 1000). The next line(s) will consist of a series of dial rotations of the form d s, where d is either C or CC (for clockwise or counterclockwise) and s (> 0) indicates how many numbers to spin through at the top of the dial. For example, if n = 50 and the current number on top of the dial is 4, the rotation CC 6 would bring the number 10 to the top, while a rotation of C 6 would bring 48 to the top. The series of dial rotations may extend over multiple lines, ending with the character ?. A line with a single 0 on it will follow the last test case. Output For each problem instance, output a single line containing either the word Open or Closed, prefaced by the test case number as shown in the sample output. Sample Input 60 6 1 58 C 114 CC 115 C 3 ? 60 6 1 58 C 54 CC 115 C 3 ? 60 6 1 58 C 54 C 60 CC 115 C 3 ? 0 Sample Output Case 1: Open Case 2: Closed Case 3: Open
Hawk-and-Chicken 程序的编写
Problem Description Kids in kindergarten enjoy playing a game called Hawk-and-Chicken. But there always exists a big problem: every kid in this game want to play the role of Hawk. So the teacher came up with an idea: Vote. Every child have some nice handkerchiefs, and if he/she think someone is suitable for the role of Hawk, he/she gives a handkerchief to this kid, which means this kid who is given the handkerchief win the support. Note the support can be transmitted. Kids who get the most supports win in the vote and able to play the role of Hawk.(A note:if A can win support from B(A != B) A can win only one support from B in any case the number of the supports transmitted from B to A are many. And A can't win the support from himself in any case. If two or more kids own the same number of support from others, we treat all of them as winner. Here's a sample: 3 kids A, B and C, A gives a handkerchief to B, B gives a handkerchief to C, so C wins 2 supports and he is choosen to be the Hawk. Input There are several test cases. First is a integer T(T <= 50), means the number of test cases. Each test case start with two integer n, m in a line (2 <= n <= 5000, 0 <m <= 30000). n means there are n children(numbered from 0 to n - 1). Each of the following m lines contains two integers A and B(A != B) denoting that the child numbered A give a handkerchief to B. Output For each test case, the output should first contain one line with "Case x:", here x means the case number start from 1. Followed by one number which is the total supports the winner(s) get. Then follow a line contain all the Hawks' number. The numbers must be listed in increasing order and separated by single spaces. Sample Input 2 4 3 3 2 2 0 2 1 3 3 1 0 2 1 0 2 Sample Output Case 1: 2 0 1 Case 2: 2 0 1 2
Think Positive 如何来实现的
Problem Description It is well known, that the year on planet Eisiem has n days. Of course, some days are very good for people, while some others are just horrible. Long observations have shown for each day of the year whether this day is good for most people, or bad. The new president of the Planet Federation wants all people to be happy. He knows that good emotions have a tendency to accumulate, just like bad ones do. The New Year however is a special event and all emotions accumulated by this moment just disappear. Therefore the president wants to change the calendar on Eisiem and choose the new first day of the year, so that the positive emotions would prevail the whole year. More precisely, for all i from 1 to n let ai be 1 if i-th day is good for most people and -1 if it is bad. Let sjk be the sum of ai for all days from the j-th day of the year to the k-th, that is: President wants to find such j to order the j-th day to be the first day of the year, that sjk is positive for all k from 1 to n. Since he wants several variants to choose from, he asks you to find all such j. Since he doesn't want to get too much information at once, first of all he wants to know the number of such j. That is exactly your task. Input The input contains multiple test cases. The first line of the input is a single integer T (1 <= T <= 30) which is the number of test cases. T test cases follow, each preceded by a single blank line. The first line of each test case contains n - the number of days (1 <= n <= 200 000). Next line contains n integer numbers - ai. Output For each case, output the number of different indices j, such that sjk is positive for all k, in a single line. Sample Input 2 5 1 -1 1 -1 1 7 1 1 1 1 1 1 1 Sample Output 1 7
The Umbrella Problem: 2054 C语言
Description "Forget it," Garret complained, throwing down the controller to his PlayStation VIII, "this level is impossible." He had just "died" for the 17th time on level 54 of the game "Lemmings 9: Lost in Space". "No it isn't," his brother Ferret replied, "and I can prove it." Ferret pulled his PlaySkool PDA from the back pocket of his Levi's Huggies. "First, picture the level as a rectangular grid." Ferret punched a few of the buttons on his PDA and a rectangle appeared as he described. "Your character, a Lemming holding an umbrella, starts at the top of this rectangle. His goal is to reach the bottom without dying." "I know that, you weasel, but what about the laser guns?" Garret whined. "The name is Ferret, and I was just getting to that. If we represent the level as a rectangular grid, then the Lemming can occupy one square and each laser gun can occupy a square. Remember the laser guns are cyclic: they all shoot up the first turn, right the second turn, down the third turn, left the fourth turn, and then repeat the sequence." "But you're forgetting the pits of lava!" Garret exclaimed. "You didn't let me finish. Each pit of lava also occupies a square. And each plot of grass, the Lemming's destination, can also occupy a square. Then, it's just a matter of manipulating the Lemming and laser beams in a series of turns to determine if it is possible for the Lemming to reach the bottom without 'dying'." "You think you're so smart, Ferret, let's see if you can explain that again in a clear, concise way." "Certainly": The level will consist of a grid of squares. The way each laser beam and the Lemming moves can be described in "turns". To determine if the Lemming can reach the bottom of the level without dying, Ferret devised some rules: Each turn will consist of two steps: First, the laser guns will "fire" and maintain until the end of the turn, a beam in a direction dependent on the number of the turn. On the first turn, each laser gun will shoot up (all squares directly above a laser gun are "unsafe" and cannot be occupied by the Lemming); on the second turn, each laser gun will shoot right; on the third turn, each laser gun will shoot down; on the fourth turn, each laser gun will shoot left; on the fifth turn, the sequence will repeat. Example: Column 01234 R 0| L |<- The Lemming will always start in a column on row 0 o 1| | In this example, on the first turn, the laser beam w 2| S | will occupy squares (3,0),(3,1); second turn, (4,2); 3| | third turn, (3,3),(3,4),(3,5),(3,6); fourth turn, 4| | (0,2),(1,2),(2,2); fifth turn (repeating), (3,0),(3,1), etc. 5| | (squares are represented using (column,row) notation) 6|GPPGG|<- The pits of lava and grass squares will always be in the last row Second, the Lemming will always move one row down, but to any one of three columns: one column to the left, one column to the right, or remain in the same column. In the above example, on the first turn the Lemming (L) could move to square (1,1), (2,1), or (3,1) (if he moved to (3,1), though, he would die because of the laser beam). However, on any turn the Lemming cannot move outside of the grid (i.e., he cannot move to column -1, or to a column number equal to the number of columns). The level is considered "possible" if the Lemming can reach any "grass" square without dying after a series of turns. The Lemming will die if at any point he occupies the same square as a laser gun, its beam, or a pit of lava. This includes: The Lemming moving into a square a pit of lava occupies, The Lemming moving into a square a laser gun occupies, The Lemming moving into a square a laser beam occupies (even if it is a grass square!), A laser gun firing a beam into a square the Lemming occupies Input Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. Each data set will describe the starting conditions of the level. A single data set has the following components: Start line - A single line, "START x y", where 0 < x < 10 and x is the number of columns in the grid representing the level and 1 < y < 10 and y is the number of rows in the grid representing the level. The next y lines will represent the rows of the level, starting with row 0 (the top). Each line will consist of x letters. The letters will represent components of the level as follows: L - Lemming (there will only be one 'L' per data set, and it will always be in row 0) S - laser gun (these squares will never be in the final row) P - pit of lava (these squares will always be in the final row) G - grass (these squares will also always be in the final row) O - "empty" square of air End line -- A single line, "END". Following the final data set will be a single line, "ENDOFINPUT". Output Output for each data set will be exactly one line. The line will either be "FERRET" or "GARRET" (both all caps with no whitespace leading or following). "FERRET" will appear if the Lemming can make it safely (without dying) to any grass square at the bottom of the level after a series of turns. "GARRET" will be output for a data set if it fails to meet the criteria for a "FERRET" line. Sample Input START 5 7 OOLOO OOOOO OOOSO OOOOO OOOOO OOOOO GPPGG END START 3 3 OLO OSO GGG END START 5 8 LOOOS OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO PPPPG END ENDOFINPUT Sample Output FERRET GARRET GARRET
C语言问题的编写，Steganography
Problem Description In cryptography, the goal is to encrypt a message so that, even if the the message is intercepted, only the intended recipient can decrypt it. In steganography, which literally means "hidden writing", the goal is to hide the fact that a message has even been sent. It has been in use since 440 BC. Historical methods of steganography include invisible inks and tatooing messages on messengers where they can't easily be seen. A modern method is to encode a message using the least-significant bits of the RGB color values of pixels in a digital image. For this problem you will uncover messages hidden in plain text. The spaces within the text encode bits; an odd number of consecutive spaces encodes a 0 and an even number of consecutive spaces encodes a 1. The four texts in the example input below (terminated by asterisks) encode the following bit strings: 11111, 000010001101101, 01, and 000100010100010011111. Each group of five consecutive bits represents a binary number in the range 0–31, which is converted to a character according to the table below. If the last group contains fewer than five bits, it is padded on the right with 0's. " " (space) 0 "A" – "Z" 1–26 "'" (apostrophe) 27 "," (comma) 28 "-" (hyphen) 29 "." (period) 30 "?" (question mark) 31 The first message is 111112 = 3110 = "?". The second message is (00001, 00011, 01101)2 = (1, 3, 13)10 = "ACM". The third message is 010002 = 810 = "H", where the underlined 0's are padding bits. The fourth message is (00010, 00101, 00010, 01111, 10000)2 = (2, 5, 2, 15, 16)10 = "BEBOP". Input The input consists of one or more texts. Each text contains one or more lines, each of length at most 80 characters, followed by a line containing only "*" (an asterisk) that signals the end of the text. A line containing only "#" signals the end of the input. In addition to spaces, text lines may contain any ASCII letters, digits, or punctuation, except for "*" and "#", which are used only as sentinels. Output For each input text, output the hidden message on a line by itself. Hidden messages will be 1–64 characters long. Note: Input text lines and output message lines conform to all of the whitespace rules listed in item 7 of Notes to Teams except that there may be consecutive spaces within a line. There will be no spaces at the beginning or end of a line. Sample Input Programmer, I would like to see a question mark. * Behold, there is more to me than you might think when you read me the first time. * Symbol for hydrogen? * A B C D E F G H I J K L M N O P Q R S T U V * # Sample Output ? ACM H BEBOP
《奇巧淫技》系列-python！！每天早上八点自动发送天气预报邮件到QQ邮箱

Linux(服务器编程):15---两种高效的事件处理模式（reactor模式、proactor模式）

C语言魔塔游戏

​ 进程通信是指进程之间的信息交换。这里需要和进程同步做一下区分，进程同步控制多个进程按一定顺序执行，进程通信是一种手段，而进程同步是目标。从某方面来讲，进程通信可以解决进程同步问题。 ​ 首先回顾下我们前面博文中讲到的信号量机制，为了实现进程的互斥与同步，需要在进程间交换一定的信息，因此信号量机制也可以被归为进程通信的一种方式，但是也被称为低级进程通信，主要原因为： 效率低：一次只可操作少量的...

Python爬虫爬取淘宝，京东商品信息

Java工作4年来应聘要16K最后没要,细节如下。。。

2020年，冯唐49岁：我给20、30岁IT职场年轻人的建议

##1、骇客帝国(1999) 概念：在线/离线，递归，循环，矩阵等 剧情简介： 不久的将来，网络黑客尼奥对这个看似正常的现实世界产生了怀疑。 他结识了黑客崔妮蒂，并见到了黑客组织的首领墨菲斯。 墨菲斯告诉他，现实世界其实是由一个名叫“母体”的计算机人工智能系统控制，人们就像他们饲养的动物，没有自由和思想，而尼奥就是能够拯救人类的救世主。 可是，救赎之路从来都不会一帆风顺，到底哪里才是真实的世界？

Python绘图，圣诞树，花，爱心 | Turtle篇

CPU对每个程序员来说，是个既熟悉又陌生的东西？ 如果你只知道CPU是中央处理器的话，那可能对你并没有什么用，那么作为程序员的我们，必须要搞懂的就是CPU这家伙是如何运行的，尤其要搞懂它里面的寄存器是怎么一回事，因为这将让你从底层明白程序的运行机制。 随我一起，来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说，我们首先就要搞明白它是怎么回事，也就是它的内部构造，当然，CPU那么牛的一个东

2020年1月17日，国家统计局发布了2019年国民经济报告，报告中指出我国人口突破14亿。 猪哥的朋友圈被14亿人口刷屏，但是很多人并没有看到我国复杂的人口问题：老龄化、男女比例失衡、生育率下降、人口红利下降等。 今天我们就来分析一下我们国家的人口数据吧！ 一、背景 1.人口突破14亿 2020年1月17日，国家统计局发布了 2019年国民经济报告 ，报告中指出：年末中国大陆总人口（包括31个

2020年的1月，我辞掉了我的第一份工作

Java坑人面试题系列: 包装类（中级难度）
Java Magazine上面有一个专门坑人的面试题系列: https://blogs.oracle.com/javamagazine/quiz-2。 这些问题的设计宗旨，主要是测试面试者对Java语言的了解程度，而不是为了用弯弯绕绕的手段把面试者搞蒙。 如果你看过往期的问题，就会发现每一个都不简单。 这些试题模拟了认证考试中的一些难题。 而 “中级(intermediate)” 和 “高级(ad

By 超神经场景描述：昨天 2 月 3 日，是大部分城市号召远程工作的第一天，全国有接近 2 亿人在家开始远程办公，钉钉上也有超过 1000 万家企业活跃起来。关键词：十一出行 人脸...
Java基础知识点梳理
Java基础知识点梳理 摘要： 虽然已经在实际工作中经常与java打交道，但是一直没系统地对java这门语言进行梳理和总结，掌握的知识也比较零散。恰好利用这段时间重新认识下java，并对一些常见的语法和知识点做个总结与回顾，一方面为了加深印象，方便后面查阅，一方面为了学好java打下基础。 Java简介 java语言于1995年正式推出，最开始被命名为Oak语言，由James Gosling（詹姆
2020年全新Java学习路线图，含配套视频，学完即为中级Java程序员！！

B 站上有哪些很好的学习资源?