POJ部分水题代码(C++)(四)

合集下载

西工大C语言POJ习题答案讲解

西工大C语言POJ习题答案讲解
int main(){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a<b)
a=b;
if(a<c)
a=c;
printf("%d\n",a);
return 0;
}
5.
#include<stdio.h>
int main()
{
int i=0,j=0,k=1;
char a[6];
e=29;
else
e=28;
switch (b)
{
case 1:n=c;break;
case 2:n=g+c;break;
case 3:n=g+e+c;break;
case 4:n=g+e+g+c;break;
case 5:n=g+e+g+f+c;break;
case 6:n=g+e+g+f+g+c;break;
b=(a-2)*1.5+7;
else b=7;
}
printf("%lf\n",b);
return 0;
}
8.
#include <stdio.h>
int main()
{
int a,b,c,e,f=30,g=31,n;
scanf("%d-%d-%d",&a,&b,&c);
if((a%400==0)||(a%100!=0&&a%4==0))
return 0;

OJ水题(适合新手)

OJ水题(适合新手)

3299HumidexTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7634 Accepted: 2967 DescriptionAdapted from Wikipedia, the free encyclopediaThe humidex is a measurement used by Canadian meteorologists to reflect the combined effect of heat and humidity. It differs from the heat index used in the United States in using dew point rather than relative humidity.When the temperature is 30°C (86°F) and the dew point is 15°C (59°F), the humidex is 34 (note that humidex is a dimensionless number, but that the number indicates an approximate temperature in C). If the temperature remains 30°C and the dew point rises to 25°C (77°F), the humidex rises to 42.3.The humidex tends to be higher than the U.S. heat index at equal temperature and relative humidity.The current formula for determining the humidex was developed by J.M. Masterton and F.A. Richardson of Canada's Atmospheric Environment Service in 1979.According to the Meteorological Service of Canada, a humidex of at least 40 causes "great discomfort" and above 45 is "dangerous." When the humidex hits 54, heat stroke is imminent.The record humidex in Canada occurred on June 20, 1953, when Windsor, Ontario hit 52.1. (The residents of Windsor would not have known this at the time, since the humidex had yet to be invented.) More recently, the humidex reached 50 on July 14, 1995 in both Windsor and Toronto.The humidex formula is as follows:humidex = temperature + hh = (0.5555)× (e - 10.0)e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))] where exp(x) is 2.718281828 raised to the exponent x.While humidex is just a number, radio announcers often announce it as if it were the temperature, e.g. "It's 47 degrees out there ... [pause] .. with the humidex,".Sometimes weather reports give the temperature and dewpoint, or the temperature and humidex, but rarely do they report all three measurements. Write a program that, given any two of the measurements, will calculate the third.You may assume that for all inputs, the temperature, dewpoint, and humidex are all between -100°C and 100°C.InputInput will consist of a number of lines. Each line except the last will consist of four items separated by spaces: a letter, a number, a second letter, and a second number. Each letter specifies the meaning of the number that follows it, and will be either T, indicating temperature, D, indicating dewpoint, or H, indicating humidex. The last line of input will consist of the single letter E.OutputFor each line of input except the last, produce one line of output. Each line of output should have the form:T number D number H numberwhere the three numbers are replaced with the temperature, dewpoint, and humidex. Each value should be expressed rounded to the nearest tenth of a degree, with exactly one digit after the decimal point. All temperatures are in degrees celsius. Sample InputT 30 D 15T 30.0 D 25.0ESample OutputT 30.0 D 15.0 H 34.0T 30.0 D 25.0 H 42.3Source2159Ancient CipherTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 16328 Accepted: 5631 DescriptionAncient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. The most popular ciphers in those times were so called substitution cipher and permutation cipher.Substitution cipher changes all occurrences of each letter to some other letter. Substitutes for all letters must be different. For some letters substitute letter may coincide with the original letter. For example, applying substitution cipher that changes all letters from 'A' to 'Y' to the next ones in the alphabet, and changes 'Z' to 'A', to the message "VICTORIOUS" one gets the message "WJDUPSJPVT". Permutation cipher applies some permutation to the letters of the message. For example, applying the permutation <2, 1, 5, 4, 3, 7, 6, 10, 9, 8> to the message "VICTORIOUS" one gets the message "IVOTCIRSUO".It was quickly noticed that being applied separately, both substitution cipher and permutation cipher were rather weak. But when being combined, they were strong enough for those times. Thus, the most important messages were first encrypted using substitution cipher, and then the result was encrypted using permutation cipher. Encrypting the message "VICTORIOUS" with the combination of the ciphers described above one gets the message "JWPUDJSTVP".Archeologists have recently found the message engraved on a stone plate. At the first glance it seemed completely meaningless, so it was suggested that the message was encrypted with some substitution and permutation ciphers. They have conjectured the possible text of the original message that was encrypted, and now they want to check their conjecture. They need a computer program to do it, so you have to write one.InputInput contains two lines. The first line contains the message engraved on the plate. Before encrypting, all spaces and punctuation marks were removed, so the encrypted message contains only capital letters of the English alphabet. The second line contains the original message that is conjectured to be encrypted in the message on the first line. It also contains only capital letters of the English alphabet.The lengths of both lines of the input are equal and do not exceed 100.OutputOutput "YES" if the message on the first line of the input file could be the result of encrypting the message on the second line, or "NO" in the other case.Sample InputJWPUDJSTVPVICTORIOUSSample OutputYES2739Sum of Consecutive Prime NumbersTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 10121 Accepted: 5743 DescriptionSome positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2+3+5+7+11+13, 11+13+17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive primenumbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20.Your mission is to write a program that reports the number of representations for the given positive integer.InputThe input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. OutputThe output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output.Sample Input231741206661253Sample Output1123121083Moving TablesTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 15442 Accepted: 5038 DescriptionThe famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job isto write a program to solve the manager's problem.InputThe input consists of T test cases. The number of test cases ) (T is given in the first line of the input file. Each test case begins with a line containing an integer N , 1 <=N <= 200, that represents the number of tables to move.Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t each room number appears at most once in the N lines). From the 3 + N -rdline, the remaining test cases are listed in the same manner as above.OutputThe output should contain the minimum time in minutes to complete the moving, one per line.Sample Input3410 2030 4050 6070 8021 32 200310 10020 8030 50Sample Output1020302262Goldbach's ConjectureTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 21791 Accepted: 8677 DescriptionIn 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture:Every even number greater than 4 can bewritten as the sum of two odd prime numbers.For example:8 = 3 + 5. Both 3 and 5 are odd prime numbers.20 = 3 + 17 = 7 + 13.42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23.Today it is still unproven whether the conjecture is right. (Oh wait, I have the proof of course, but it is too long to write it on the margin of this page.)Anyway, your task is now to verify Goldbach's conjecture for all even numbers less than a million.InputThe input will contain one or more test cases.Each test case consists of one even integer n with 6 <= n < 1000000.Input will be terminated by a value of 0 for n.OutputFor each test case, print one line of the form n = a + b, where a and b are odd primes. Numbers and operators should be separated by exactly one blank like in the sample output below. If there is more than one pair of odd primes adding up to n, choose the pair where the difference b - a is maximized. If there is no such pair, print a line saying "Goldbach's conjecture is wrong."Sample Input82042Sample Output8 = 3 + 520 = 3 + 1742 = 5 + 371503Integer InquiryTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 18304 Accepted: 7176 DescriptionOne of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers.``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)InputThe input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).The final input line will contain a single zero on a line by itself.OutputYour program should output the sum of the VeryLongIntegers given in the input. Sample Input123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890Sample Output3703703670370370367037037036703006Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9221 Accepted: 4601 DescriptionIf a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., a, a + d, a + 2d, a + 3d, a + 4d, ..., contains infinitely many prime numbers. This fact is known as Dirichlet's Theorem on Arithmetic Progressions, which had been conjectured by Johann Carl Friedrich Gauss (1777 - 1855) and was proved by Johann Peter Gustav Lejeune Dirichlet (1805 - 1859) in 1837.For example, the arithmetic sequence beginning with 2 and increasing by 3, i.e.,2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, ... ,contains infinitely many prime numbers2, 5, 11, 17, 23, 29, 41, 47, 53, 59, 71, 83, 89, ... .Your mission, should you decide to accept it, is to write a program to find the n th prime number in this arithmetic sequence for given positive integers a, d, and n. InputThe input is a sequence of datasets. A dataset is a line containing three positive integers a, d, and n separated by a space. a and d are relatively prime. You may assume a <= 9307, d <= 346, and n <= 210.The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.OutputThe output should be composed of as many lines as the number of the input datasets. Each line should contain a single integer and should never contain extra characters.The output integer corresponding to a dataset a, d, n should be the n th prime number among those contained in the arithmetic sequence beginning with a and increasing by d.FYI, it is known that the result is always less than 106 (one million) under this input condition.Sample Input367 186 151179 10 203271 37 39103 230 127 104 185253 50 851 1 19075 337 210307 24 79331 221 177259 170 40269 58 1020 0 0Sample Output9280967091203710393523145032899429510741271722699256732255Tree RecoveryTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4999 Accepted: 3330 DescriptionLittle Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital letters in the nodes.This is an example of one of her creations:D/ \/ \B E/ \ \/ \ \A C G//FTo record her trees for future generations, she wrote down two strings for each tree: a preorder traversal (root, left subtree, right subtree) and an inorder traversal (left subtree, root, right subtree). For the tree drawn above the preorder traversal is DBACEGF and the inorder traversal is ABCDEFG.She thought that such a pair of strings would give enough information to reconstruct the tree later (but she never tried it).Now, years later, looking again at the strings, she realized that reconstructing the trees was indeed possible, but only because she never had used the same letter twice in the same tree.However, doing the reconstruction by hand, soon turned out to be tedious.So now she asks you to write a program that does the job for her!InputThe input will contain one or more test cases.Each test case consists of one line containing two strings preord and inord, representing the preorder traversal and inorder traversal of a binary tree. Both strings consist of unique capital letters. (Thus they are not longer than 26 characters.)Input is terminated by end of file.OutputFor each test case, recover Valentine's binary tree and print one line containing the tree's postorder traversal (left subtree, right subtree, root).Sample InputDBACEGF ABCDEFGBCAD CBADSample OutputACBFGEDCDABSource3094QuicksumTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8033 Accepted: 5592 DescriptionA checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data.For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. Otherwise, spaces and letters can occur in any combination, including consecutive spaces.A Quicksum is the sum of the products of each character's position in the packet times the character's value. A space has a value of zero, while letters have a value equal to their position in the alphabet. So, A=1, B=2, etc., through Z=26. Here are example Quicksum calculations for the packets "ACM" and "MID CENTRAL":ACM: 1*1 + 2*3 + 3*13 = 46MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650InputThe input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.OutputFor each packet, output its Quicksum on a separate line in the output.Sample InputACMMID CENTRALREGIONAL PROGRAMMING CONTESTACNA C MABCBBC#Sample Output46650469049751415 Source。

POJ水题题目

POJ水题题目

POJ 1247 Magnificent MeatballsMagnificent MeatballsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 5719Accepted: 3837DescriptionSam and Ella run a catering service. They like to put on a show when serving meatballs to guests seated at round tables. They march out of the kitchen with pots of meatballs and start serving adjacent guests. Ella goes counterclockwise and Sam goes clockwise, until they both plop down their last meatball, at the same time, again at adjacent guests. This impressive routine can only be accomplished if they can divide the table into two sections, each having the same number of meatballs. You are to write a program to assist them.At these catering events, each table seats 2 <= N <= 30 guests. Each guest orders at least one and at most nine meatballs. Each place at the table is numbered from 1 to N, with the host at position 1 and the host's spouse at position N. Sam always serves the host first then proceeds to serve guests in increasing order. Ella serves the spouse first, then serves guests in decreasing order. The figures illustrate the first two example input cases.InputInput consists of one or more test cases. Each test case contains the number of guests N followed by meatballs ordered by each guest, from guest 1 to guest N. The end of the input is a line with a single zero.OutputFor each table, output a single line with the ending positions for Sam and Ella, or the sentence indicating an equal partitioning isn't possible. Use the exact formatting shown below.Sample Input5 9 4 2 8 35 3 9 4 2 86 1 2 1 2 1 26 1 2 1 2 1 1Sample OutputSam stops at position 2 and Ella stops at position 3.No equal partitioning.No equal partitioning.Sam stops at position 3 and Ella stops at position 4.SourceMid-Central USA 2002POJ 1316 Self NumbersSelf NumbersTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 18000Accepted: 10125DescriptionIn 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. For any positive integer n, define d(n) to be n plus the sum of the digits of n. (The d stands for digitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting point, you can construct the infinite increasing sequence of integers n, d(n), d(d(n)), d(d(d(n))), .... For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next is 51 + 5 + 1 = 57, and so you generate the sequence33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ...The number n is called a generator of d(n). In the sequence above, 33 is a generator of 39, 39 is a generator of 51, 51 is a generator of 57, and so on. Some numbers have more than one generator: for example, 101 has two generators, 91 and 100. A number with no generators is a self-number.There are thirteen self-numbers less than 100: 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97.InputNo input for this problem.OutputWrite a program to output all positive self-numbers less than 10000 in increasing order, one per line.Sample InputSample Output135792031425364|| <-- a lot more numbers|9903991499259927993899499960997199829993SourceMid-Central USA 1998POJ 1488 TEX QuotesTEX QuotesTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 7464Accepted: 3925DescriptionTEX is a typesetting language developed by Donald Knuth. It takes source text together with a few typesetting instructions and produces, one hopes, a beautiful document. Beautiful documents use double-left-quote and double-right-quote to delimit quotations, rather than the mundane " which is what is provided by most keyboards. Keyboards typically do not have an oriented double-quote, but they do have a left-single-quote ` and a right-single-quote '. Check your keyboard now to locate the left-single-quote key ` (sometimes called the "backquote key") and the right-single-quote key ' (sometimes called the "apostrophe" or just "quote"). Be careful not to confuse the left-single-quote ` with the "backslash" key \. TEX lets the user type two left-single-quotes `` to create a left-double-quote and two right-single-quotes '' to create a right-double-quote. Most typists, however, are accustomed to delimiting their quotations with the un-oriented double-quote ".If the source contained"To be or not to be," quoth the bard, "that is the question."then the typeset document produced by TEX would not contain the desired form: "To be or not to be," quoth the bard, "that is the question." In order to produce the desired form, the source file must contain the sequence:``To be or not to be,'' quoth the bard, ``that is the question.''You are to write a program which converts text containing double-quote (") characters into text that is identical except that double-quotes have been replaced by the two-character sequences required by TEX for delimiting quotations with oriented double-quotes. The double-quote (") characters should be replaced appropriately by either `` if the " opens a quotation and by '' if the " closes a quotation. Notice that the question of nested quotations does not arise: The first " must be replaced by ``, the next by '', the next by ``, the next by '', the next by ``, the next by '', and so on.InputInput will consist of several lines of text containing an even number of double-quote (") characters. Input is ended with an end-of-file character.OutputThe text must be output exactly as it was input except that:∙the first " in each pair is replaced by two ` characters: `` and∙the second " in each pair is replaced by two ' characters: ''.Sample Input"To be or not to be," quoth the Bard, "thatis the question".The programming contestant replied: "I must disagree.To `C' or not to `C', that is The Question!"Sample Output``To be or not to be,'' quoth the Bard, ``thatis the question''.The programming contestant replied: ``I must disagree.To `C' or not to `C', that is The Question!''SourceEast Central North America 1994POJ 1493 Machined SurfacesMachined SurfacesTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2173Accepted: 1408DescriptionAn imaging device furnishes digital images of two machined surfaces that eventually will be assembled in contact with each other. The roughness of this final contact is to be estimated.A digital image is composed of the two characters, "X" and " " (space). There are always 25 columns to an image, but the number of rows, N, is variable. Column one (1) will always have an "X" in it and will be part of the left surface. The left surface can extend to the right from column one (1) as contiguous X's.Similarly, column 25 will always have an "X" in it and will be part of the right surface. The right surface can extend to the left from column 25 as contiguous X's.Digital-Image View of SurfacesLeft RightXXXX XXXXX ←1XXX XXXXXXXXXXXX XXXXXX XXXXXX. .. .. .XXXX XXXXXXX XXXXX ←N↑↑1 25In each row of the image, there can be zero or more space characters separating the left surface from the right surface. There will never be more than a single blank region in any row.For each image given, you are to determine the total ``void" that will exist after the left surface has been brought into contact with the right surface. The ``void" is the total count of the spaces that remains between the left and right surfaces after theyhave been brought into contact.The two surfaces are brought into contact by displacing them strictly horizontally towards each other until a rightmost "X" of the left surface of some row is immediately to the left of the leftmost "X" of the right surface of that row. There is no rotation or twisting of these two surfaces as they are brought into contact; they remain rigid, and only move horizontally.Note: The original image may show the two surfaces already in contact, in which case no displacement enters into the contact roughness estimation.InputThe input consists of a series of digital images. Each image data set has the following format:First line -A single unsigned integer, N, with value greater than zero (0) and less than 13. The first digit of N will be the first character on a line.Next N lines -Each line has exactly 25 characters; one or more X's, then zero or more spaces, then one or more X's.The end of data is signaled by a null data set having a zero on the first line of an image data set and no further data.OutputFor each image you receive as a data set, you are to reply with the total void (count of spaces remaining after the surfaces are brought into contact). Use the default output for a single integer on a line.Sample Input4XXXX XXXXXXXX XXXXXXXXXXXX XXXXXX XXXXXX2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXXXXXXX XXSample OutputSourceEast Central North America 1995POJ 1517 u Calculate eu Calculate eTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 15876 Accepted: 9555 Special Judge DescriptionA simple mathematical formula for e ise=Σ0<=i<=n1/i!where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.InputNo inputOutputOutput the approximations of e generated by the above formula for the values of n from 0 to 9. The beginning of your output should appear similar to that shown below. Sample Inputno inputSample Outputn e- -----------0 11 22 2.53 2.6666666674 2.708333333...POJ 1519 Digital RootsDigital RootsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 23459Accepted: 7790DescriptionThe digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.InputThe input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.OutputFor each integer in the input, output its digital root on a separate line of the output.Sample Input2439Sample Output63SourceGreater New York 2000POJ 1545 Galactic ImportGalactic ImportTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 276Accepted: 143DescriptionWith the introduction of the new ThrustoZoom gigadimensional drive, it has become possible for HyperCommodities, the import/export conglomerate from New Jersey, to begin trading with even the most remote galaxies in the universe. HyperCommodities wants to import goods from some of the galaxies in the Plural Z sector. Planets within these galaxies export valuable products and raw materials like vacuuseal, transparent aluminum, digraphite, and quantum steel. Preliminary reports have revealed the following facts:∙Each galaxy contains at least one and at most 26 planets. Each planet within a galaxy is identified by a unique letter from A to Z.∙Each planet specializes in the production and export of one good. Different planets within the same galaxy export different goods.∙Some pairs of planets are connected by hyperspace shipping lines. If planets A and B are connected, they can trade goods freely. If planet C is connected to B but not to A, then Aand C can still trade goods with each other through B, but B keeps 5% of the shipment asa shipping fee. (Thus A only receives 95% of what C shipped, and C receives only 95% ofwhat A shipped.) In general, any two planets can trade goods as long as they areconnected by some set of shipping lines, but each intermediate planet along the shippingroute keeps 5% of what it shipped (which is not necessarily equal to 5% of the originalshipment).∙At least one planet in each galaxy is willing to open a ThrustoZoom shipping line to Earth.A ThrustoZoom line is the same as any other shipping line within the galaxy, as far asbusiness is concerned. For example, if planet K opens a ThrustoZoom line to Earth, thenthe Earth can trade goods freely with K, or it can trade goods with any planet connectedto K, subject to the usual shipping fees.HyperCommodities has assigned a relative value (a positive real number less than 10) to each planet's chief export. The higher the number, the more valuable the product. More valuable products can be resold with a higher profit margin in domestic markets. The problem is to determine which planet has the most valuable export when shipping fees are taken into account.InputThe input consists of one or more galaxy descriptions. Each galaxy description begins with a line containing an integer N which specifies the number of planets in the galaxy. The next N lines contain descriptions of each planet, which consist of:1.The letter used to represent the planet.2. A space.3.The relative value of the planet's export, in the form d.dd.4. A space.5. A string containing letters and/or the character `*'; a letter indicates a shipping line to thatplanet, and a `*' indicates a willingness to open a ThrustoZoom shipping line to Earth. OutputFor each galaxy description, output a single line which reads "Import from P" where P is the letter of the planet with the most valuable export, once shipping fees have been taken into account. (If more than one planet have the same most valuable export value then output the plant which is alphabetically first).Sample Input1F 0.81 *5E 0.01 *AD 0.01 A*C 0.01 *AA 1.00 EDCBB 0.01 A*10S 2.23 Q*A 9.76 CK 5.88 MIE 7.54 GCM 5.01 OKG 7.43 IEI 6.09 KGC 8.42 EAO 4.55 QMQ 3.21 SOSample OutputImport from FImport from AImport from ASourceMid-Central USA 1995POJ 1547 Clay BullyClay BullyTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 7660Accepted: 4309DescriptionMs. Terry is a pre-school art teacher who likes to have her students work with clay. One of her assignments is to form a lump of clay into a block and then measure the dimensions of the block. However, in every class, there is always one child who insists on taking some clay from some other child. Since Ms. Terry always gives every child in a class the same amount of clay to begin with, you can write a program that helps Ms. Terry find the bully and victim after she measures each child's finished block.InputThere are one or more classes of students, followed by a final line containing only the value -1. Each class starts with a line containing an integer, n, which is the number of students in the class, followed by n lines of student information. Each line of student information consists of three positive integers, representing the dimensions of the clay block, followed by the student's first name. There can never be more than 9 students nor less than 2 students in any class. Each student's name is at most 8 characters. Ms. Terry always gives each student at most 250 cubic units of clay. There is exactly one bully and one victim in each class.OutputFor each class print a single line exactly as shown in the sample output.Sample Input310 10 2 Jill5 3 10 Will5 5 10 Bill42 4 10 Cam4 3 7 Sam8 11 1 Graham6 27 Pam-1Sample OutputBill took clay from Will.Graham took clay from Cam.SourceMid-Central USA 2003POJ 1552 DoublesDoublesTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 16404Accepted: 9390DescriptionAs part of an arithmetic competency program, your students will be given randomly generated lists of from 2 to 15 unique positive integers and asked to determine how many items in each list are twice some other item in the same list. You will need a program to help you with the grading. This program should be able to scan the lists and output the correct answer for each one. For example, given the list1 4 32 9 7 18 22your program should answer 3, as 2 is twice 1, 4 is twice 2, and 18 is twice 9.InputThe input will consist of one or more lists of numbers. There will be one list of numbers per line. Each list will contain from 2 to 15 unique positive integers. No integer will be larger than 99. Each line will be terminated with the integer 0, which is not considered part of the list. A line with the single number -1 will mark the end of the file. The example input below shows 3 separate lists. Some lists may not contain any doubles.OutputThe output will consist of one line per input list, containing a count of the items that are double some other item.Sample Input1 4 32 9 7 18 22 02 4 8 10 07 5 11 13 1 3 0-1Sample Output32SourceMid-Central USA 2003POJ 1575 Easier Done Than Said?Easier Done Than Said?Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3711Accepted: 2068DescriptionPassword security is a tricky thing. Users prefer simple passwords that are easy to remember (like buddy), but such passwords are often insecure. Some sites use random computer-generated passwords (like xvtpzyo), but users have a hard time remembering them and sometimes leave them written on notes stuck to their computer. One potential solution is to generate "pronounceable" passwords that are relatively secure but still easy to remember.FnordCom is developing such a password generator. You work in the quality control department, and it's your job to test the generator and make sure that the passwords are acceptable. To be acceptable, a password must satisfy these three rules:It must contain at least one vowel.It cannot contain three consecutive vowels or three consecutive consonants.It cannot contain two consecutive occurrences of the same letter, except for 'ee' or 'oo'.(For the purposes of this problem, the vowels are 'a', 'e', 'i', 'o', and 'u'; all other letters are consonants.) Note that these rules are not perfect; there are many common/pronounceable words that are not acceptable.InputThe input consists of one or more potential passwords, one per line, followed by a line containing only the word 'end' that signals the end of the file. Each password is at least one and at most twenty letters long and consists only of lowercase letters.OutputFor each password, output whether or not it is acceptable, using the precise format shown in the example.Sample InputatvptouibontreszoggaxwiinqeephouctuhendSample Output<a> is acceptable.<tv> is not acceptable.<ptoui> is not acceptable.<bontres> is not acceptable.<zoggax> is not acceptable.<wiinq> is not acceptable.<eep> is acceptable.<houctuh> is acceptable.SourceMid-Central USA 2000POJ 1657 Distance on ChessboardDistance on ChessboardTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 21169Accepted: 7296 Description国际象棋的棋盘是黑白相间的8 * 8的方格,棋子放在格子中间。

2011_C++_POJ习题表

2011_C++_POJ习题表

10 1 2 3 4 1 9 −1 2 −3 A = 2 −1 7 3 −5 3 2 3 12 −1 4 −3 −5 −1 15
T0804 T0811 编写函数实现快速排序(降序) ,在主函数中输入数组数据(7,12,-88,23,44,8,33, -100,11,22) 并调用该数得到排序结果。 编写 fun 函数,函数的功能是移动一维数组中的内容;若数组中有 n 个整数,要求把下标从 0 到 p(含 p,p 小干等于 n-1)的数组元素平移到数组的最后。例如,一维数组中的原始内容 为:1,2,3,4,5,6,7,8,9,10;p 的值为 3。移动后,一维数组中的内容应为:5,6, 7,8,9,10,1,2,3,4。在主函数中输入数据并调用函数得到结果。 编写 fun 函数 int fun(int a[], int n),删去一维数组中所有相同的数,使之只剩一个。数组中的 数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。例如,一维数组中的数据是: 2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10,删除后,数组中的内容应该是:2 3 4 5 6 7 8 9 10。在 主函数中输入数据并调用函数得到结果。 编写函数按下列公式计算 s 的值,函数头为 double s(double x[],int n)。
方括号内为“刘君瑞《C++程序设计习题与解析》”指定章节的程序设计题号
方括号内为“魏英《C++程序设计实验教程》”第 3 章各节的设计型实验题号
《教材》无来源习题题面 题号 CH0510 CH0613 CH0707 CH0714 习题内容 有 4 个圆塔,圆心分别为(2,2)、(-2,2)、(2,-2)、(-2,-2),圆半径为 1。这 4 个塔的高度分 别为 10m。塔以外无建筑物。今输入任一点的坐标,求该点的建筑高度(塔外的高度为零)。 用二分法求方程在(-10,10)之间的根 打印“魔方阵”,所谓魔方阵是指这样的方阵,它的每一行、每一列和对角线之和均相等。 编一个程序, 将两个字符串 S1 和 S2 比较, 如果 S1>S2, 输出一个正数; S1=S2, 输出 0; S1<S2, 输出一个负数。不要用 strcpy 函数。两个字符串用 gets 函数读入。输出的正数或负数的绝对值 应是相比较的两个字符串相对应字符的 ASCII 码的差值。例如,’A’与’C’相比,由于’A’<’C’,应输 出负数,由于’A’与’C’的码差值为 2,因此应输出"-2"。同理:"And"和"Aid"比较,根据第 2 个字 符比较结果,’n’比’i’大 5,因此应输出"5"。 输入 10 个学生 5 门课的成绩,分别用函数求:①每个学生平均分;②每门课的平均分;③找 出最高分所对应的学生和课程;④求平均分方差:δ=[SXi^2]/n-(SXi/n)^2,为一学生的平均分 将一个链表按逆序排列,即将链头当链尾,链尾当链头。 设计一个函数,使给出一个数的原码,能得到该数的补码。

POJ2054ColoraTree#贪心(难,好题)

POJ2054ColoraTree#贪心(难,好题)

POJ2054ColoraTree#贪⼼(难,好题)代码借鉴此博:其中关于max{c[fa]/t[fa]}贪⼼原则,此博有很好的解释:在此引⽤其中⼏段话:试想,如果没有⽗节点排在节点之前的限制,那么这个题⽬⾮常简单,只需要将结点按照权值从⼤到⼩排列即可。

加上了这个限制之后,如果权值最⼤的那个节点⼀旦满⾜了条件(⽗节点被排在了之前的某个位置),那么这个权值最⼤的节点⼀定要紧挨着这个⽗节点,即把这个权值最⼤的节点排在它所能排的最前⾯的位置。

因为对于这个节点如果不受限制应该排在第⼀位,⽽有了限制,在满⾜了限制之后也应把它尽可能地排在前⾯。

所以它⼀定是挨着⽗节点的。

那么现在在最终的排列中我们确定了两个节点的前后相邻关系,将他们绑定在了⼀起。

试想如果保持这个相邻关系的同时去掉其他节点的限制,那么我们应该如何排列呢?我们假设绑定在⼀起的两节点是a和b。

现有⼀个另外的节点x,我们看两种排列xab,abx对最终的计算结果有什么影响。

x*i+a*(i+1)+b*(i+2); a*i + b*(i+1) + x*(i+2)。

后者减去前者等于2x-(a+b)。

即将x从ab之前挪到ab之后,ab各左移1位,结果减⼩a+b。

x右移2位结果增加2x。

因此两者谁在前谁在后我们只需要⽐较a+b和2x即可,也可以⽐较(a+b)/2和x。

将这个定理进⾏⼀下推⼴,绑定在⼀起的不⼀定是两个节点,可以是⼀个更长的序列,与这个序列进⾏⽐较看谁放在前⾯的也可以是⼀个序列。

设⼀个序列有n1个节点,第⼆个序列有n2个节点。

那么我们⽐较两者谁放在前⾯的时候需要⽐较的是(n1个权值之和×n2)和(n2个权值之和×n1)。

即左移和右移产⽣的结果变化。

当然也可以⽐较(n1个权值之和/n1)和(n2个权值之和/n2)。

我们可以再次进⾏推⼴,如果我们要排列的不是节点,⽽是许多序列的话,那么我们只需要计算每个序列权值的平均数(例如:n个节点的序列,要计算n个权值之和/n),然后按照这个平均数从⼤到⼩排列即可使得计算结果最⼩。

POJ 题目整理

POJ 题目整理

初期:一.基本算法:(1)枚举. (poj1753,poj2965)(2)贪心(poj1328,poj2109,poj2586)(3)递归和分治法.(4)递推.(5)构造法.(poj3295)(6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:(1)图的深度优先遍历和广度优先遍历.(2)最短路径算法(dijkstra,bellman-ford,floyd,heap+dijkstra)(poj1860,poj3259,poj1062,poj2253,poj1125,poj2240)(3)最小生成树算法(prim,kruskal) (poj1789,poj2485,poj1258,poj3026)(4)拓扑排序 (poj1094)(5)二分图的最大匹配 (匈牙利算法) (poj3041,poj3020)(6)最大流的增广路算法(KM算法). (poj1459,poj3436)三.数据结构.(1)串 (poj1035,poj3080,poj1936)(2)排序(快排、归并排(与逆序数有关)、堆排) (poj2388,poj2299)(3)简单并查集的应用.(4)哈希表和二分查找等高效查找法(数的Hash,串的Hash)(poj3349,poj3274,POJ2151,poj1840,poj2002,poj2503)(5)哈夫曼树(poj3253)(6)堆(7)trie树(静态建树、动态建树) (poj2513)四.简单搜索(1)深度优先搜索 (poj2488,poj3083,poj3009,poj1321,poj2251)(2)广度优先搜索(poj3278,poj1426,poj3126,poj3087.poj3414)(3)简单搜索技巧和剪枝(poj2531,poj1416,poj2676,1129)五.动态规划(1)背包问题. (poj1837,poj1276)(2)型如下表的简单DP(可参考lrj的书 page149):1.E[j]=opt{D+w(i,j)} (poj3267,poj1836,poj1260,poj2533)2.E[i,j]=opt{D[i-1,j]+xi,D[i,j-1]+yj,D[i-1][j-1]+zij} (最长公共子序列) (poj3176,poj1080,poj1159)3.C[i,j]=w[i,j]+opt{C[i,k-1]+C[k,j]}.(最优二分检索树问题)六.数学(1)组合数学:1.加法原理和乘法原理.2.排列组合.3.递推关系.(POJ3252,poj1850,poj1019,poj1942)(2)数论.1.素数与整除问题2.进制位.3.同余模运算.(poj2635, poj3292,poj1845,poj2115)(3)计算方法.1.二分法求解单调函数相关知识.(poj3273,poj3258,poj1905,poj3122)七.计算几何学.(1)几何公式.(2)叉积和点积的运用(如线段相交的判定,点到线段的距离等). (poj2031,poj1039)(3)多边型的简单算法(求面积)和相关判定(点在多边型内,多边型是否相交)(poj1408,poj1584)(4)凸包. (poj2187,poj1113)中级:一.基本算法:(1)C++的标准模版库的应用. (poj3096,poj3007)(2)较为复杂的模拟题的训练(poj3393,poj1472,poj3371,poj1027,poj2706)二.图算法:(1)差分约束系统的建立和求解. (poj1201,poj2983)(2)最小费用最大流(poj2516,poj2516,poj2195)(3)双连通分量(poj2942)(4)强连通分支及其缩点.(poj2186)(5)图的割边和割点(poj3352)(6)最小割模型、网络流规约(poj3308, )三.数据结构.(1)线段树. (poj2528,poj2828,poj2777,poj2886,poj2750)(2)静态二叉检索树. (poj2482,poj2352)(3)树状树组(poj1195,poj3321)(4)RMQ. (poj3264,poj3368)(5)并查集的高级应用. (poj1703,2492)(6)KMP算法. (poj1961,poj2406)四.搜索(1)最优化剪枝和可行性剪枝(2)搜索的技巧和优化 (poj3411,poj1724)(3)记忆化搜索(poj3373,poj1691)五.动态规划(1)较为复杂的动态规划(如动态规划解特别的施行商问题等) (poj1191,poj1054,poj3280,poj2029,poj2948,poj1925,poj3034)(2)记录状态的动态规划. (POJ3254,poj2411,poj1185)(3)树型动态规划(poj2057,poj1947,poj2486,poj3140)六.数学(1)组合数学:1.容斥原理.2.抽屉原理.3.置换群与Polya定理(poj1286,poj2409,poj3270,poj1026).4.递推关系和母函数.(2)数学.1.高斯消元法(poj2947,poj1487, poj2065,poj1166,poj1222)2.概率问题. (poj3071,poj3440)3.GCD、扩展的欧几里德(中国剩余定理) (poj3101)(3)计算方法.1.0/1分数规划. (poj2976)2.三分法求解单峰(单谷)的极值.3.矩阵法(poj3150,poj3422,poj3070)4.迭代逼近(poj3301)(4)随机化算法(poj3318,poj2454)(5)杂题. (poj1870,poj3296,poj3286,poj1095)七.计算几何学.(1)坐标离散化.(2)扫描线算法(例如求矩形的面积和周长并,常和线段树或堆一起使用).(poj1765,poj1177,poj1151,poj3277,poj2280,poj3004)(3)多边形的内核(半平面交)(poj3130,poj3335)(4)几何工具的综合应用.(poj1819,poj1066,poj2043,poj3227,poj2165,poj3429)高级:一.基本算法要求:(1)代码快速写成,精简但不失风格(poj2525,poj1684,poj1421,poj1048,poj2050,poj3306)(2)保证正确性和高效性. poj3434二.图算法:(1)度限制最小生成树和第K最短路. (poj1639)(2)最短路,最小生成树,二分图,最大流问题的相关理论(主要是模型建立和求解) (poj3155, poj2112,poj1966,poj3281,poj1087,poj2289,poj3216,poj2446) (3)最优比率生成树. (poj2728)(4)最小树形图(poj3164)(5)次小生成树.(6)无向图、有向图的最小环三.数据结构.(1)trie图的建立和应用. (poj2778)(2)LCA和RMQ问题(LCA(最近公共祖先问题) 有离线算法(并查集+dfs) 和在线算法(RMQ+dfs)).(poj1330)(3)双端队列和它的应用(维护一个单调的队列,常常在动态规划中起到优化状态转移的目的).(poj2823)(4)左偏树(可合并堆).(5)后缀树(非常有用的数据结构,也是赛区考题的热点). (poj3415,poj3294)四.搜索(1)较麻烦的搜索题目训练(poj1069,poj3322,poj1475,poj1924,poj2049,poj3426)(2)广搜的状态优化:利用M进制数存储状态、转化为串用hash表判重、按位压缩存储状态、双向广搜、A*算法. (poj1768,poj1184,poj1872,poj1324,poj2046,poj1482)(3)深搜的优化:尽量用位运算、一定要加剪枝、函数参数尽可能少、层数不易过大、可以考虑双向搜索或者是轮换搜索、IDA*算法.(poj3131,poj2870,poj2286)五.动态规划(1)需要用数据结构优化的动态规划. (poj2754,poj3378,poj3017)(2)四边形不等式理论.(3)较难的状态DP(poj3133)六.数学(1)组合数学.1.MoBius反演(poj2888,poj2154)2.偏序关系理论.(2)博奕论.1.极大极小过程(poj3317,poj1085)2.Nim问题.七.计算几何学.(1)半平面求交(poj3384,poj2540)(2)可视图的建立(poj2966)(3)点集最小圆覆盖.(4)对踵点(poj2079)八.综合题.(poj3109,poj1478,poj1462,poj2729,poj2048,poj3336,poj3315,poj2148,poj1263) 以及补充Dp状态设计与方程总结1.不完全状态记录<1>青蛙过河问题<2>利用区间dp2.背包类问题<1> 0-1背包,经典问题<2>无限背包,经典问题<3>判定性背包问题<4>带附属关系的背包问题<5> + -1背包问题<6>双背包求最优值<7>构造三角形问题<8>带上下界限制的背包问题(012背包)3.线性的动态规划问题<1>积木游戏问题<2>决斗(判定性问题)<3>圆的最大多边形问题<4>统计单词个数问题<5>棋盘分割<6>日程安排问题<7>最小逼近问题(求出两数之比最接近某数/两数之和等于某数等等)<8>方块消除游戏(某区间可以连续消去求最大效益)<9>资源分配问题<10>数字三角形问题<11>漂亮的打印<12>邮局问题与构造答案<13>最高积木问题<14>两段连续和最大<15>2次幂和问题<16>N个数的最大M段子段和<17>交叉最大数问题4.判定性问题的dp(如判定整除、判定可达性等)<1>模K问题的dp<2>特殊的模K问题,求最大(最小)模K的数<3>变换数问题5.单调性优化的动态规划<1>1-SUM问题<2>2-SUM问题<3>序列划分问题(单调队列优化)6.剖分问题(多边形剖分/石子合并/圆的剖分/乘积最大)<1>凸多边形的三角剖分问题<2>乘积最大问题<3>多边形游戏(多边形边上是操作符,顶点有权值)<4>石子合并(N^3/N^2/NLogN各种优化)7.贪心的动态规划<1>最优装载问题<2>部分背包问题<3>乘船问题<4>贪心策略<5>双机调度问题Johnson算法8.状态dp<1>牛仔射击问题(博弈类)<2>哈密顿路径的状态dp<3>两支点天平平衡问题<4>一个有向图的最接近二部图9.树型dp<1>完美服务器问题(每个节点有3种状态)<2>小胖守皇宫问题<3>网络收费问题<4>树中漫游问题<5>树上的博弈<6>树的最大独立集问题<7>树的最大平衡值问题<8>构造树的最小环转一个搞ACM需要的掌握的算法.要注意,ACM的竞赛性强,因此自己应该和自己的实际应用联系起来.适合自己的才是好的,有的人不适合搞算法,喜欢系统架构,因此不要看到别人什么就眼红, 发挥自己的长处,这才是重要的.第一阶段:练经典常用算法,下面的每个算法给我打上十到二十遍,同时自己精简代码,因为太常用,所以要练到写时不用想,10-15分钟内打完,甚至关掉显示器都可以把程序打出来.1.最短路(Floyd、Dijstra,BellmanFord)2.最小生成树(先写个prim,kruscal要用并查集,不好写)3.大数(高精度)加减乘除4.二分查找. (代码可在五行以内)5.叉乘、判线段相交、然后写个凸包.6.BFS、DFS,同时熟练hash表(要熟,要灵活,代码要简)7.数学上的有:辗转相除(两行内),线段交点、多角形面积公式.8. 调用系统的qsort, 技巧很多,慢慢掌握.9. 任意进制间的转换第二阶段:练习复杂一点,但也较常用的算法。

POJ部分水题代码(C++) (一)

POJ部分水题代码(C++) (一)

P O J1000p r o g r a m p1000(I n p u t,O u t p u t);v a ra,b:I n t e g e r;b e g i nR e a d l n(a,b);W r i t e l n(a+b);e n d.P O J1004#i n c l u d e<i o s t r e a m>#i n c l u d e<i o m a n i p>u s i n g n a m e s p a c e s t d;i n t m a i n(){f l o a t a,b;u n s i g n e d i n t c;c i n>>a;b=a;f o r(c=1;c<12;c++){c i n>>b;a+=b;}b=a/12;c o u t<<"$"<<b<<f i x e d<<s e t p r e c i s i o n(2)<<e nd l;r e t u r n0;}/**********************author KINGRAIN@EECS_PKUtime May 16,2010dormpoj1013称硬币***********************/#include <iostream>#include <cstring>using namespace std;bool isLight(char);bool isHeavy(char);char Left[3][7]={0},Right[3][7]={0};int result[3];int main(){int n=0,k,j; char letter,resul[5];cin >> n;for (int i=0; i<n; i++){for (j=0; j<3; j++){cin >> Left[j] >> Right[j] >> resul;if (strcmp(resul,"up")==0)result[j] = 1;if (strcmp(resul,"even")==0)result[j] = 2;if (strcmp(resul,"down")==0)result[j] = 3;}for (letter='A'; letter<='L'; letter++){if (isLight(letter)){cout << letter << " is the counterfeit coin and it is light.\n";break;}else if (isHeavy(letter)){cout << letter << " is the counterfeit coin and it is heavy.\n";break;}}}return 0;}bool isLight(char ch){for (int i=0; i<3; i++){switch(result[i]){case 1: if (strchr(Right[i],ch)==0)return 0;break;case 2: if ((strchr(Right[i],ch)!=0)||(strchr(Left[i],ch)!=0))return 0;break;case 3: if (strchr(Left[i],ch)==0)return 0;break;}}return 1;}bool isHeavy(char ch){for (int i=0; i<3; i++){switch(result[i]){case 1: if (strchr(Left[i],ch)==0)return 0;break;case 2: if ((strchr(Right[i],ch)!=0)||(strchr(Left[i],ch)!=0))return 0;break;case 3: if (strchr(Right[i],ch)==0)return 0;break;}return 1;}/**********************author KINGRAIN@EECS_PKUtime Mar.5,2010dormpoj1017装箱问题***********************/#include <iostream>#include <cstring>using namespace std;int main(){int b[6],i,nTotal=0,roomForBox2[4]={0,5,3,1},maxBox2=0,maxBox1_1=0;do{for (i=0; i<6; i++)cin >> b[i];if ((b[0]==0)&&(b[1]==0)&&(b[2]==0)&&(b[3]==0)&&(b[4]==0)&&(b[5]==0))break;nTotal = b[5]+b[4]+b[3]+(b[2]+3)/4;maxBox2 = 5*b[3]+roomForBox2[(b[2])%4];if (b[1]>maxBox2)nTotal += (b[1]-maxBox2+8)/9;maxBox1_1 = nTotal*36-36*b[5]-25*b[4]-16*b[3]-9*b[2]-4*b[1];if (b[0]>maxBox1_1)nTotal += (b[0]-maxBox1_1+35)/36;printf("%d\n",nTotal);} while (1);return 0;}/**********************author KINGRAIN@EECS_PKUdormpoj1088滑雪***********************/#include <iostream>using namespace std;const int SIZE = 110;struct POINT{int height;int x;int y;} position[SIZE*SIZE] = {0}; // 记录点的高度坐标int length[SIZE][SIZE]={0},height[SIZE][SIZE]={0};int Mycompare(const void *,const void *);int Max(int,int);// 算法就是先找出凹点将其长度值为一// 点length[i][j] = max{点length[i-1][j],点length[i+1][j],点length[i][j-1],点length[i][j+1]} 前提是这些点比它高……int main(){int R=0,C=0,i=0,n=0,j=0,k=0,LONGEST = 0;cin >> R >> C;for (i=1; i<=R; i++)for (j=1; j<=C; j++){cin >> height[i][j];position[k].height = height[i][j];position[k].x = j;position[k++].y = i;}qsort(position,k,sizeof(position[0]),Mycompare); // 将点按高度排列for (j=0; j<=C; j++) // 将边沿置为最大值在后面处理较为方便height[0][j] = 999999, height[R+1][j] = 999999;for (j=0; j<=R; j++)height[j][0] = 999999, height[j][C+1] = 999999;for (i=1; i<=R; i++)for (j=1; j<=C; j++){if ((height[i][j]<=height[i+1][j])&&(height[i][j]<=height[i-1][j]) // 对于凹点长度就为一&&(height[i][j]<=height[i][1+j])&&(height[i][j]<=height[i][j-1]))length[i][j] = 1;}for (i=0; i<k; i++){if (length[position[i].y][position[i].x]==1)continue;else{if (height[position[i].y][position[i].x]>height[position[i].y][position[i].x+1])length[position[i].y][position[i].x] = length[position[i].y][position[i].x+1] + 1;if (height[position[i].y][position[i].x]>height[position[i].y][position[i].x-1])length[position[i].y][position[i].x]= Max(length[position[i].y][position[i].x],length[position[i].y][position[i].x-1]+1);if (height[position[i].y][position[i].x]>height[position[i].y+1][position[i].x])length[position[i].y][position[i].x]= Max(length[position[i].y][position[i].x],length[position[i].y+1][position[i].x]+1);if (height[position[i].y][position[i].x]>height[position[i].y-1][position[i].x])length[position[i].y][position[i].x]= Max(length[position[i].y][position[i].x],length[position[i].y-1][position[i].x]+1);}}for (i=1; i<=R; i++)for (j=1; j<=C; j++)if (LONGEST<length[i][j])LONGEST = length[i][j];printf("%d\n",LONGEST);return 0;}int Mycompare(const void *elem1,const void *elem2) // 按升序排列{POINT *ptr1,*ptr2;ptr1 = (POINT *) elem1;ptr2 = (POINT *) elem2;return (ptr1->height-ptr2->height);}int Max(int a, int b){if (a>=b)return a;elsereturn b; }/**********************author KINGRAIN@EECS_PKUtime May 22,2010computer room 159poj1095Trees made to order***********************/#include <iostream>using namespace std;void Creat_Tree(int );int Trees_amount[25]={0};int Tree_last_order[25]={0};int wmain(){int i=0,j=0,m=0,n=0;Trees_amount[0] = Trees_amount[1] = 1;Trees_amount[2] = 2;Tree_last_order[0] = 0;Tree_last_order[1] = 1;Tree_last_order[2] = 3;for (i=3; i<25; i++){for (j=0; j<i; j++)Trees_amount[i] += Trees_amount[j]*Trees_amount[i-1-j];Tree_last_order[i] = Tree_last_order[i-1] + Trees_amount[i];}while (cin>>n){if (n==0)break;Creat_Tree(n);cout << endl;}return 0;}void Creat_Tree(int n){int i,j;for (i=0; n>Tree_last_order[i]; i++); // 循环结束时此棵树上共有i 个节点n -= Tree_last_order[i-1]; // 这是i 个节点的第n棵树for (j=0; j<i; j++) // 右树一共有i-1-j个节点左树一共有j个节点{if (n<=Trees_amount[i-1-j]*Trees_amount[j])break;elsen -= Trees_amount[i-1-j]*Trees_amount[j];}if (j!=0){cout << '(';Creat_Tree((n-1)/Trees_amount[i-1-j]+1+Tree_last_order[j-1]);cout << ')';}cout << 'X';if ((i-1-j)!=0){cout << '(';Creat_Tree((n-1)%Trees_amount[i-j-1]+1+Tree_last_order[i-j-2]);cout << ')';}}/**********************author KINGRAIN@EECS_PKUtime April 2,2010classroompoj1163The Triangle***********************/#include <iostream>using namespace std;const int MAX = 110;int highestSum[MAX][MAX] = {0},position[MAX][MAX]={0}; // high[] 记录最大值,position[]记录位置存储的值inline int Max(int, int);int main(){int n=0,j=0,i=0;cin >> n;for (i=0; i<n; i++)for (j=0; j<=i; j++)cin >> position[i][j];for (i=0; i<n; i++)highestSum[n-1][i] = position[n-1][i]; // 初始化最底层的最大值for (i=n-2; i>=0; i--)for (j=0; j<=i; j++) // 递推关系式当前的最大值等于上一步的最大值加当前节点数值highestSum[i][j] = Max(highestSum[i+1][j],highestSum[i+1][j+1]) + position[i][j];printf("%d\n",highestSum[0][0]);return 0;}inline int Max(int a, int b){if (a>b)return a;elsereturn b;}/**********************author KINGRAIN@EECS_PKUtime April 2,2010computerroompoj2815城堡问题***********************/#include <iostream>using namespace std;int Move(int, int, bool);const int M=55,N=55;int CASTLE[M][N]={0},m=0,n=0,state[M][N]={0},Room=0;int main(){int j=0,i=0,k=0,t=0,Max_area=0,area=0;cin >> m >> n;for (i=0; i<m; i++)for (j=0; j<n; j++)cin >> CASTLE[i][j];for (i=0; i<m; i++)for (j=0; j<n; j++) // 以每个位置为出发点,让假想的小人出发。

poj字符串模拟题

poj字符串模拟题

poj字符串模拟题含详解POJ(Peking University Online Judge)是一个经典的在线评测系统,提供了许多算法和数据结构相关的问题。

字符串模拟题通常涉及到对字符串进行一系列操作,模拟实际情景。

以下是一个POJ上的一个字符串模拟题,附有详细解释。

题目:POJ 3617 - Best Cow Line#题目描述:有一个长度为N(1 ≤N ≤2,000)的字符串,字符串中的每个字符是'A' 或'B'。

现在有两个人要从字符串的两端开始走,每个人每次可以选择当前所在的端点的字符拼接到自己的字符串末尾。

请问,最后谁的字符串字典序较小?#输入:-第1 行:一个整数N-接下来N 行:每行一个字符,为'A' 或'B'#输出:-一行字符串,表示较小字典序的字符串#样例输入:```6ABABAA```#样例输出:```ABAA```#解释:一种最优策略是,从字符串两端选择字符,比较字典序。

根据题目描述,两个人轮流选择字符拼接到字符串末尾。

在这个例子中,第一个人可以选择A,第二个人可以选择B,然后轮到第一个人又选择A,接着是B,最后是A。

所以最后的结果是"ABAA"。

#解答:```cpp#include <iostream>#include <string>using namespace std;int main() {int N;cin >> N;string s;for (int i = 0; i < N; ++i) {char c;cin >> c;s += c;}int left = 0, right = N - 1;string result;while (left <= right) {bool isLeftSmaller = false;for (int i = 0; left + i <= right; ++i) {if (s[left + i] < s[right - i]) {isLeftSmaller = true;break;} else if (s[left + i] > s[right - i]) {isLeftSmaller = false;break;}}if (isLeftSmaller) {result += s[left++];} else {result += s[right--];}}cout << result << endl;return 0;}```这个程序首先读取输入,然后使用两个指针`left` 和`right` 分别指向字符串的开头和结尾。

POJC++程序设计编程题#7:字符串排序

POJC++程序设计编程题#7:字符串排序

POJC++程序设计编程题#7:字符串排序编程题#7:字符串排序来源: 北京⼤学在线程序评测系统POJ (Coursera声明:在POJ上完成的习题将不会计⼊Coursera的最后成绩。

)总时间限制: 1000ms 内存限制: 1024kB描述请按照要求对输⼊的字符串进⾏排序。

#include <iostream>#include <string>#include <list>using namespace std;class A{private:string name;public:A(string n) :name(n){}friend bool operator < (const class A& a1, const class A &a2);friend bool operator == (const class A &a1, const class A &a2){if (.size() == .size())return true;elsereturn false;}friend ostream & operator << (ostream &o, const A &a){o << ;return o;}string get_name() const{return name;}int get_size() const{return name.size();}};// 在此处补充你的代码int main(int argc, char* argv[]){list<A> lst;int ncase, n, i = 1;string s;cin >> ncase;while (ncase--){cout << "Case: "<<i++ << endl;cin >> n;for (int i = 0; i < n; i++){cin >> s;lst.push_back(A(s));}lst.sort();Show(lst.begin(), lst.end(), Print());cout << endl;lst.sort(MyLarge<A>());Show(lst.begin(), lst.end(), Print());cout << endl;lst.clear();}return 0;}输⼊第⼀⾏是正整数T,表⽰测试数据的组数每组测试数据输⼊共两⾏,第⼀⾏是正整数N,表⽰字符串个数第⼆⾏是N个字符串, 字符串间⽤空格分离输出对于每组测试数据,先输出⼀⾏:Case: n如对第⼀组数据就输出Case: 1第⼆⾏按照字符串长度从⼩到⼤排序之后输出N个字符串,字符串之间以空格间隔(不会出现字符串长度相同的情况)第三⾏按照字符串⾸字符ASCII码序从⼩到⼤排序之后输出N个字符串,字符串之间以空格间隔(不会出现字符串⾸字母相同的情况)样例输⼊24a bnss ds tsdfasg5aaa bbbb ccccd sa q样例输出Case: 1a ds bnss tsdfasga bnss ds tsdfasgCase: 2q sa aaa bbbb ccccdaaa bbbb ccccd q sa1 #include <iostream>2 #include <string>3 #include <list>4using namespace std;56class A{7private:8string name;9public:10 A(string n) :name(n){}11 friend bool operator < (const class A& a1, const class A &a2);12 friend bool operator == (const class A &a1, const class A &a2){13if (.size() == .size())14return true;15else16return false;17 }18 friend ostream & operator << (ostream &o, const A &a){19 o << ;20return o;21 }22string get_name() const{23return name;24 }25int get_size() const{26return name.size();27 }28 };29// 在此处补充你的代码30bool operator< (const A& a1, const A &a2) {31return .size() < .size();32 };3334 template <class Iterator, class Function>35void Show(Iterator begin, Iterator end, Function print) {36for (Iterator iterator1 = begin; iterator1 != end; iterator1++) {37 print(*iterator1);38 }39 };4041class Print {42public:43void operator()(const A &a) {44 cout << a.get_name()<< "";45 }46 };4748 template <class A>49struct MyLarge {50 inline bool operator()(const A &a1, const A &a2) { 51return a1.get_name() < a2.get_name();52 }53 };5455int main(int argc, char* argv[])56 {57 list<A> lst;58int ncase, n, i = 1;59string s;60 cin >> ncase;61while (ncase--){62 cout << "Case: "<<i++ << endl;63 cin >> n;64for (int i = 0; i < n; i++){65 cin >> s;66 lst.push_back(A(s));67 }68 lst.sort();69 Show(lst.begin(), lst.end(), Print());7071 cout << endl;72 lst.sort(MyLarge<A>());73 Show(lst.begin(), lst.end(), Print());74 cout << endl;75 lst.clear();76 }77return0;78 }。

北大 poj acm题目推荐50题

北大 poj acm题目推荐50题

-北大poj acm题目推荐50题POJ == 北京大学ACM在线评测系统/JudgeOnline1. 标记难和稍难的题目大家可以看看,思考一下,不做要求,当然有能力的同学可以直接切掉。

2. 标记为A and B 的题目是比较相似的题目,建议大家两个一起做,可以对比总结,且二者算作一个题目。

3. 列表中大约有70个题目。

大家选做其中的50道,且每类题目有最低数量限制。

4. 这里不少题目在BUPT ACM FTP 上面都有代码,请大家合理利用资源。

5. 50个题目要求每个题目都要写总结,养成良好的习惯。

6. 这50道题的规定是我们的建议,如果大家有自己的想法请与我们Email 联系。

7. 建议使用C++ 的同学在POJ 上用G++ 提交。

8. 形成自己编写代码的风格,至少看上去美观,思路清晰(好的代码可以很清楚反映出解题思路)。

9. 这个列表的目的在于让大家对各个方面的算法有个了解,也许要求有些苛刻,教条,请大家谅解,这些是我们这些年的经验总结,所以也请大家尊重我们的劳动成果。

10. 提交要求:一个总文件夹名为bupt0xx (即你的比赛帐号), 这个文件夹内有各个题目类别的子目录(文件夹),将相应的解题报告放入对应类别的文件夹。

在本学期期末,小学期开始前,将该文件夹的压缩包发至buptacm@。

对于每个题目只要求一个POJxxxx.cpp 或POJxxxx.java (xxxx表示POJ该题题号) 的文件,注意不要加入整个project 。

11. 如果有同学很早做完了要求的题目,请尽快和我们联系,我们将指导下一步的训练。

下面是一个解题报告的范例:例如:POJ1000.cpp//考查点:会不会编程序。

//思路:此题要求输入两个数,输出两个数的和,我用scanf 和printf。

//提交情况:Wrong Answer 1次,忘了写printf()。

Compile Error 2次,选错了语言,由于C++ 和G++ 在iostream.h 的不用引用方法;少一个大括号。

POJ多例题版

POJ多例题版

POJ多例题版目录一、数的距离差二、按十一位切换整数至英文单词三、将字符串中的小写字母转换成大写字母四、最长最短单词五、计算绩点六、按要求排序七、计算多项式的值八、计算两个分数的和九、登山十、排序平均年龄十一、数圈十二、摆苹果十三、计算约数的和十四、冒泡排序十五、结构代莱模运算十六、最小最小值十七、最大公约数与最小公倍数十八、计算素数的和十九、任意进制间转换二十、二项式系数二十一、成仙(poj2733)二十二、日历问题(poj2964)二十三、爬楼梯(poj4017)二十四、大整数加法(poj2981)二十五、肿瘤检测(poj2677)二十六、肿瘤面积(poj2713)二十七、不吉利日期(poj2723)二十八、八进制到十进制(poj2735)二十九、分解因数(poj2749)三十、垂直直方图(poj2800)三十一、取石子游戏(poj1067)三十二、分数加减法(poj3979)一.数的距离高给定一组正整数,其中的最大值和最小值分别为max和min,其中的一个数x到max和min的距离差d定义为abs(abs(x-max)-abs(x-min))。

其中,abs()则表示谋一个数的绝对值输出输入第一行为整数n,剩余n行每行一个正整数。

输出输入仅一行,它的值使距离差d最轻的x。

样例输出531759样例输出提示函数abs()定义在stdlib.h中例:(一)#include#include#definen400intmain(){inta[n],d[n];inti,n,max,m,min,d_min;scanf (\for(i=0;id[i]){d_min=d[i];m=a[i];}}printf(\return0;}(二)#include#include#definen500intmain(){inta[n],n,i,m,p,r,s,t;scanf(\for(i=0;ia[i ])}m=a[i];if(ps=abs(abs(a[0]-p)-abs(a[0]-m));t=a[0];for(i=1;ir){s=r;t=a[i];}}printf(\return0;二、按十一位切换整数至英文单词题目叙述请把输入整数的每位数字转换成英文。

北大poj题目分类

北大poj题目分类

初期:一.基本算法:(1)枚举. (poj1753,poj2965)(2)贪心(poj1328,poj2109,poj2586)(3)递归和分治法.(4)递推.(5)构造法.(poj3295)(6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:(1)图的深度优先遍历和广度优先遍历.(2)最短路径算法(dijkstra,bellman-ford,floyd,heap+dijkstra)(poj1860,poj3259,poj1062,poj2253,poj1125,poj2240)(3)最小生成树算法(prim,kruskal)(poj1789,poj2485,poj1258,poj3026)(4)拓扑排序(poj1094)(5)二分图的最大匹配(匈牙利算法) (poj3041,poj3020)(6)最大流的增广路算法(KM算法). (poj1459,poj3436)三.数据结构.(1)串(poj1035,poj3080,poj1936)(2)排序(快排、归并排(与逆序数有关)、堆排) (poj2388,poj2299)(3)简单并查集的应用.(4)哈希表和二分查找等高效查找法(数的Hash,串的Hash)(poj3349,poj3274,POJ2151,poj1840,poj2002,poj2503)(5)哈夫曼树(poj3253)(6)堆(7)trie树(静态建树、动态建树) (poj2513)四.简单搜索(1)深度优先搜索(poj2488,poj3083,poj3009,poj1321,poj2251)(2)广度优先搜索(poj3278,poj1426,poj3126,poj3087.poj3414)(3)简单搜索技巧和剪枝(poj2531,poj1416,poj2676,1129)五.动态规划(1)背包问题. (poj1837,poj1276)(2)型如下表的简单DP(可参考lrj的书page149):1.E[j]=opt{D+w(i,j)} (poj3267,poj1836,poj1260,poj2533)2.E[i,j]=opt{D[i-1,j]+xi,D[i,j-1]+yj,D[i-1][j-1]+zij} (最长公共子序列)(poj3176,poj1080,poj1159)3.C[i,j]=w[i,j]+opt{C[i,k-1]+C[k,j]}.(最优二分检索树问题)六.数学(1)组合数学:1.加法原理和乘法原理.2.排列组合.3.递推关系.(POJ3252,poj1850,poj1019,poj1942)(2)数论.1.素数与整除问题2.进制位.3.同余模运算.(poj2635, poj3292,poj1845,poj2115)(3)计算方法.1.二分法求解单调函数相关知识.(poj3273,poj3258,poj1905,poj3122)七.计算几何学.(1)几何公式.(2)叉积和点积的运用(如线段相交的判定,点到线段的距离等). (poj2031,poj1039)(3)多边型的简单算法(求面积)和相关判定(点在多边型内,多边型是否相交)(poj1408,poj1584)(4)凸包. (poj2187,poj1113)中级:一.基本算法:(1)C++的标准模版库的应用. (poj3096,poj3007)(2)较为复杂的模拟题的训练(poj3393,poj1472,poj3371,poj1027,poj2706)二.图算法:(1)差分约束系统的建立和求解. (poj1201,poj2983)(2)最小费用最大流(poj2516,poj2516,poj2195)(3)双连通分量(poj2942)(4)强连通分支及其缩点.(poj2186)(5)图的割边和割点(poj3352)(6)最小割模型、网络流规约(poj3308, )三.数据结构.(1)线段树. (poj2528,poj2828,poj2777,poj2886,poj2750)(2)静态二叉检索树. (poj2482,poj2352)(3)树状树组(poj1195,poj3321)(4)RMQ. (poj3264,poj3368)(5)并查集的高级应用. (poj1703,2492)(6)KMP算法. (poj1961,poj2406)四.搜索(1)最优化剪枝和可行性剪枝(2)搜索的技巧和优化(poj3411,poj1724)(3)记忆化搜索(poj3373,poj1691)五.动态规划(1)较为复杂的动态规划(如动态规划解特别的施行商问题等)(poj1191,poj1054,poj3280,poj2029,poj2948,poj1925,poj3034)(2)记录状态的动态规划. (POJ3254,poj2411,poj1185)(3)树型动态规划(poj2057,poj1947,poj2486,poj3140)六.数学(1)组合数学:1.容斥原理.2.抽屉原理.3.置换群与Polya定理(poj1286,poj2409,poj3270,poj1026).4.递推关系和母函数.(2)数学.1.高斯消元法(poj2947,poj1487, poj2065,poj1166,poj1222)2.概率问题. (poj3071,poj3440)3.GCD、扩展的欧几里德(中国剩余定理) (poj3101)(3)计算方法.1.0/1分数规划. (poj2976)2.三分法求解单峰(单谷)的极值.3.矩阵法(poj3150,poj3422,poj3070)4.迭代逼近(poj3301)(4)随机化算法(poj3318,poj2454)(5)杂题.(poj1870,poj3296,poj3286,poj1095)七.计算几何学.(1)坐标离散化.(2)扫描线算法(例如求矩形的面积和周长并,常和线段树或堆一起使用).(poj1765,poj1177,poj1151,poj3277,poj2280,poj3004)(3)多边形的内核(半平面交)(poj3130,poj3335)(4)几何工具的综合应用.(poj1819,poj1066,poj2043,poj3227,poj2165,poj3429)高级:一.基本算法要求:(1)代码快速写成,精简但不失风格(poj2525,poj1684,poj1421,poj1048,poj2050,poj3306)(2)保证正确性和高效性. poj3434二.图算法:(1)度限制最小生成树和第K最短路. (poj1639)(2)最短路,最小生成树,二分图,最大流问题的相关理论(主要是模型建立和求解)(poj3155, poj2112,poj1966,poj3281,poj1087,poj2289,poj3216,poj2446(3)最优比率生成树. (poj2728)(4)最小树形图(poj3164)(5)次小生成树.(6)无向图、有向图的最小环三.数据结构.(1)trie图的建立和应用. (poj2778)(2)LCA和RMQ问题(LCA(最近公共祖先问题) 有离线算法(并查集+dfs) 和在线算法(RMQ+dfs)).(poj1330)(3)双端队列和它的应用(维护一个单调的队列,常常在动态规划中起到优化状态转移的目的). (poj2823)(4)左偏树(可合并堆).(5)后缀树(非常有用的数据结构,也是赛区考题的热点).(poj3415,poj3294)四.搜索(1)较麻烦的搜索题目训练(poj1069,poj3322,poj1475,poj1924,poj2049,poj3426)(2)广搜的状态优化:利用M进制数存储状态、转化为串用hash表判重、按位压缩存储状态、双向广搜、A*算法. (poj1768,poj1184,poj1872,poj1324,poj2046,poj1482)(3)深搜的优化:尽量用位运算、一定要加剪枝、函数参数尽可能少、层数不易过大、可以考虑双向搜索或者是轮换搜索、IDA*算法. (poj3131,poj2870,poj2286)五.动态规划(1)需要用数据结构优化的动态规划.(poj2754,poj3378,poj3017)(2)四边形不等式理论.(3)较难的状态DP(poj3133)六.数学(1)组合数学.1.MoBius反演(poj2888,poj2154)2.偏序关系理论.(2)博奕论.1.极大极小过程(poj3317,poj1085)2.Nim问题.七.计算几何学.(1)半平面求交(poj3384,poj2540)(2)可视图的建立(poj2966)(3)点集最小圆覆盖.(4)对踵点(poj2079)八.综合题.(poj3109,poj1478,poj1462,poj2729,poj2048,poj3336,poj3315,poj2148,poj1263)以及补充Dp状态设计与方程总结1.不完全状态记录<1>青蛙过河问题<2>利用区间dp2.背包类问题<1> 0-1背包,经典问题<2>无限背包,经典问题<3>判定性背包问题<4>带附属关系的背包问题<5> + -1背包问题<6>双背包求最优值<7>构造三角形问题<8>带上下界限制的背包问题(012背包)3.线性的动态规划问题<1>积木游戏问题<2>决斗(判定性问题)<3>圆的最大多边形问题<4>统计单词个数问题<5>棋盘分割<6>日程安排问题<7>最小逼近问题(求出两数之比最接近某数/两数之和等于某数等等)<8>方块消除游戏(某区间可以连续消去求最大效益)<9>资源分配问题<10>数字三角形问题<11>漂亮的打印<12>邮局问题与构造答案<13>最高积木问题<14>两段连续和最大<15>2次幂和问题<16>N个数的最大M段子段和<17>交叉最大数问题4.判定性问题的dp(如判定整除、判定可达性等)<1>模K问题的dp<2>特殊的模K问题,求最大(最小)模K的数<3>变换数问题5.单调性优化的动态规划<1>1-SUM问题<2>2-SUM问题<3>序列划分问题(单调队列优化)6.剖分问题(多边形剖分/石子合并/圆的剖分/乘积最大)<1>凸多边形的三角剖分问题<2>乘积最大问题<3>多边形游戏(多边形边上是操作符,顶点有权值)<4>石子合并(N^3/N^2/NLogN各种优化)7.贪心的动态规划<1>最优装载问题<2>部分背包问题<3>乘船问题<4>贪心策略<5>双机调度问题Johnson算法8.状态dp<1>牛仔射击问题(博弈类)<2>哈密顿路径的状态dp<3>两支点天平平衡问题<4>一个有向图的最接近二部图9.树型dp<1>完美服务器问题(每个节点有3种状态)<2>小胖守皇宫问题<3>网络收费问题<4>树中漫游问题<5>树上的博弈<6>树的最大独立集问题<7>树的最大平衡值问题<8>构造树的最小环。

题单解题记录-POJ题目分类推荐(很好很有层次感)

题单解题记录-POJ题目分类推荐(很好很有层次感)

题单解题记录-POJ题⽬分类推荐(很好很有层次感)题单链接:11.6poj1753 -60min 1A sol:枚举中⼼点,1个点只有2个⽅案(翻/不翻),枚举要翻的点的⽅案。

poj1328 -55min CE-T-W-A sol:->线段重叠取最少点选到所有线段。

细节:位置相同左点排前。

2*n个点依次⼊栈,右点⼊栈则栈中线段共⽤1点(相应vis置1),然后清空栈。

poj1860 -3h=180min W-A 啊好慢!! sol:->找图中有⽆某个环,转⼀圈财富增加,若存在,则可以转⾜够多的圈直到原路⾛回S还能是正利润。

这个环中不必包含S,但是实际找的过程中如果能找到环则必是从S能⾛到这个环。

没⽤bellman-ford算法(其实想到了,但是看复杂度想直接⼿写,不存邻接表),⽽是循环了所有边,若当前边的起点被更新过,则更新终点的值,我认为这样能满⾜“所有被更新过的点必是从S能⾛到的点”。

(虽然没⽤模板但是还是⾃⼰思考出了类似bf的思路) WA代码⽐AC代码多了这么⼀句错误“优化”(循环边的过程中如果更新了之前更新过的点则确定已找到财富增加的环):if(pt[e[i].b]>eps)printf("YES");return0;} 错因:唉我指定是忽略了⼀种情况,但是⽬前还没构造出来(poj1789 -40min RE-A sol:->并查集总边权。

RE原因:int findf(int x){if(f[x]!=x)return f[x]=findf(f[x]);} findf函数写成这粑粑样了,f[x]==x时没返回值/吐⾎。

poj1035 -17min 1A sol:复习三个常⽤字符串函数⽤法。

坑:函数⾥定义char[]⼀定⼀定要memset初始化!!poj2388 -40min W-A sol:注意:快排的基准值是值不是下标,所以不可能⽤它实现O(N)找第K⼤。

poj分类

poj分类

vector:Constructors 构造函数Operators 对vector进行赋值或比较assign() 对Vector中的元素赋值at() 返回指定位置的元素back() 返回最末一个元素begin() 返回第一个元素的迭代器capacity() 返回vector所能容纳的元素数量(在不重新分配内存的情况下)clear() 清空所有元素empty() 判断Vector是否为空(返回true时为空)end() 返回最末元素的迭代器(译注:实指向最末元素的下一个位置)erase() 删除指定元素front() 返回第一个元素get_allocator() 返回vector的内存分配器insert() 插入元素到Vector中max_size() 返回Vector所能容纳元素的最大数量(上限)pop_back() 移除最后一个元素push_back() 在Vector最后添加一个元素rbegin() 返回Vector尾部的逆迭代器rend() 返回Vector起始的逆迭代器reserve() 设置Vector最小的元素容纳数量resize() 改变Vector元素数量的大小size() 返回Vector元素数量的大小swap() 交换两个Vectorlist:assign() 给list赋值back() 返回最后一个元素begin() 返回指向第一个元素的迭代器clear() 删除所有元素empty() 如果list是空的则返回trueend() 返回末尾的迭代器erase() 删除一个元素front() 返回第一个元素get_allocator() 返回list的配置器insert() 插入一个元素到list中max_size() 返回list能容纳的最大元素数量merge() 合并两个listpop_back() 删除最后一个元素pop_front() 删除第一个元素push_back() 在list的末尾添加一个元素push_front() 在list的头部添加一个元素rbegin() 返回指向第一个元素的逆向迭代器remove() 从list删除元素remove_if() 按指定条件删除元素rend() 指向list末尾的逆向迭代器resize() 改变list的大小reverse() 把list的元素倒转size() 返回list中的元素个数sort() 给list排序splice() 合并两个listswap() 交换两个listunique() 删除list中重复的元素stack:操作比较和分配堆栈empty() 堆栈为空则返回真pop() 移除栈顶元素push() 在栈顶增加元素size() 返回栈中元素数目top() 返回栈顶元素queue:back() 返回最后一个元素empty() 如果队列空则返回真front() 返回第一个元素pop() 删除第一个元素push() 在末尾加入一个元素size() 返回队列中元素的个数转】ACM训练计划OJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3 094)初期:一.基本算法:(1)枚举. (poj1753,poj2965)(2)贪心(poj1328,poj2109,poj2586)(3)递归和分治法.(4)递推.(5)构造法.(poj3295)(6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:(1)图的深度优先遍历和广度优先遍历.(2)最短路径算法(dijkstra,bellman-ford,floyd,heap+dijkstra)(poj1860,poj3259,poj1062,poj2253,poj1125,poj2240)(3)最小生成树算法(prim,kruskal)(poj1789,poj2485,poj1258,poj3026)(4)拓扑排序 (poj1094)(5)二分图的最大匹配 (匈牙利算法) (poj3041,poj3020)(6)最大流的增广路算法(KM算法). (poj1459,poj3436)三.数据结构.(1)串 (poj1035,poj3080,poj1936)(2)排序(快排、归并排(与逆序数有关)、堆排) (poj2388,poj2299)(3)简单并查集的应用.(4)哈希表和二分查找等高效查找法(数的Hash,串的Hash)(poj3349,poj3274,POJ2151,poj1840,poj2002,poj2503)(5)哈夫曼树(poj3253)(6)堆(7)trie树(静态建树、动态建树) (poj2513)四.简单搜索(1)深度优先搜索 (poj2488,poj3083,poj3009,poj1321,poj2251)(2)广度优先搜索(poj3278,poj1426,poj3126,poj3087.poj3414)(3)简单搜索技巧和剪枝(poj2531,poj1416,poj2676,1129)五.动态规划(1)背包问题. (poj1837,poj1276)(2)型如下表的简单DP(可参考lrj的书 page149):1.E[j]=opt{D+w(i,j)} (poj3267,poj1836,poj1260,poj2533)2.E[i,j]=opt{D[i-1,j]+xi,D[i,j-1]+yj,D[i-1][j-1]+zij} (最长公共子序列)(poj3176,poj1080,poj1159)3.C[i,j]=w[i,j]+opt{C[i,k-1]+C[k,j]}.(最优二分检索树问题)六.数学(1)组合数学:1.加法原理和乘法原理.2.排列组合.3.递推关系.(POJ3252,poj1850,poj1019,poj1942)(2)数论.1.素数与整除问题2.进制位.3.同余模运算.(poj2635, poj3292,poj1845,poj2115)(3)计算方法.1.二分法求解单调函数相关知识.(poj3273,poj3258,poj1905,poj3122)七.计算几何学.(1)几何公式.(2)叉积和点积的运用(如线段相交的判定,点到线段的距离等).(poj2031,poj1039)(3)多边型的简单算法(求面积)和相关判定(点在多边型内,多边型是否相交)(poj1408,poj1584)(4)凸包. (poj2187,poj1113)中级:一.基本算法:(1)C++的标准模版库的应用. (poj3096,poj3007)(2)较为复杂的模拟题的训练(poj3393,poj1472,poj3371,poj1027,poj2706)二.图算法:(1)差分约束系统的建立和求解. (poj1201,poj2983)(2)最小费用最大流(poj2516,poj2516,poj2195)(3)双连通分量(poj2942)(4)强连通分支及其缩点.(poj2186)(5)图的割边和割点(poj3352)(6)最小割模型、网络流规约(poj3308, )三.数据结构.(1)线段树. (poj2528,poj2828,poj2777,poj2886,poj2750)(2)静态二叉检索树. (poj2482,poj2352)(3)树状树组(poj1195,poj3321)(4)RMQ. (poj3264,poj3368)(5)并查集的高级应用. (poj1703,2492)(6)KMP算法. (poj1961,poj2406)四.搜索(1)最优化剪枝和可行性剪枝(2)搜索的技巧和优化 (poj3411,poj1724)(3)记忆化搜索(poj3373,poj1691)五.动态规划(1)较为复杂的动态规划(如动态规划解特别的施行商问题等)(poj1191,poj1054,poj3280,poj2029,poj2948,poj1925,poj3034)(2)记录状态的动态规划. (POJ3254,poj2411,poj1185)(3)树型动态规划(poj2057,poj1947,poj2486,poj3140)六.数学(1)组合数学:1.容斥原理.2.抽屉原理.3.置换群与Polya定理(poj1286,poj2409,poj3270,poj1026).4.递推关系和母函数.(2)数学.1.高斯消元法(poj2947,poj1487, poj2065,poj1166,poj1222)2.概率问题. (poj3071,poj3440)3.GCD、扩展的欧几里德(中国剩余定理) (poj3101)(3)计算方法.1.0/1分数规划. (poj2976)2.三分法求解单峰(单谷)的极值.3.矩阵法(poj3150,poj3422,poj3070)4.迭代逼近(poj3301)(4)随机化算法(poj3318,poj2454)(5)杂题.(poj1870,poj3296,poj3286,poj1095)七.计算几何学.(1)坐标离散化.(2)扫描线算法(例如求矩形的面积和周长并,常和线段树或堆一起使用).(poj1765,poj1177,poj1151,poj3277,poj2280,poj3004)(3)多边形的内核(半平面交)(poj3130,poj3335)(4)几何工具的综合应用.(poj1819,poj1066,poj2043,poj3227,poj2165,poj3429)高级:一.基本算法要求:(1)代码快速写成,精简但不失风格(poj2525,poj1684,poj1421,poj1048,poj2050,poj3306)(2)保证正确性和高效性. poj3434二.图算法:(1)度限制最小生成树和第K最短路. (poj1639)(2)最短路,最小生成树,二分图,最大流问题的相关理论(主要是模型建立和求解)(poj3155,poj2112,poj1966,poj3281,poj1087,poj2289,poj3216,poj2446(3)最优比率生成树. (poj2728)(4)最小树形图(poj3164)(5)次小生成树.(6)无向图、有向图的最小环三.数据结构.(1)trie图的建立和应用. (poj2778)(2)LCA和RMQ问题(LCA(最近公共祖先问题) 有离线算法(并查集+dfs) 和在线算法(RMQ+dfs)).(poj1330)(3)双端队列和它的应用(维护一个单调的队列,常常在动态规划中起到优化状态转移的目的). (poj2823)(4)左偏树(可合并堆).(5)后缀树(非常有用的数据结构,也是赛区考题的热点).(poj3415,poj3294)四.搜索(1)较麻烦的搜索题目训练(poj1069,poj3322,poj1475,poj1924,poj2049,poj3426)(2)广搜的状态优化:利用M进制数存储状态、转化为串用hash表判重、按位压缩存储状态、双向广搜、A*算法.(poj1768,poj1184,poj1872,poj1324,poj2046,poj1482)(3)深搜的优化:尽量用位运算、一定要加剪枝、函数参数尽可能少、层数不易过大、可以考虑双向搜索或者是轮换搜索、IDA*算法.(poj3131,poj2870,poj2286)五.动态规划(1)需要用数据结构优化的动态规划.(poj2754,poj3378,poj3017)(2)四边形不等式理论.(3)较难的状态DP(poj3133)六.数学(1)组合数学.1.MoBius反演(poj2888,poj2154)2.偏序关系理论.(2)博奕论.1.极大极小过程(poj3317,poj1085)2.Nim问题.七.计算几何学.(1)半平面求交(poj3384,poj2540)(2)可视图的建立(poj2966)(3)点集最小圆覆盖.(4)对踵点(poj2079)八.综合题.(poj3109,poj1478,poj1462,poj2729,poj2048,poj3336,poj3315,poj214 8,poj1263)----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------以及补充Dp状态设计与方程总结1.不完全状态记录<1>青蛙过河问题<2>利用区间dp2.背包类问题<1> 0-1背包,经典问题<2>无限背包,经典问题<3>判定性背包问题<4>带附属关系的背包问题<5> + -1背包问题<6>双背包求最优值<7>构造三角形问题<8>带上下界限制的背包问题(012背包)3.线性的动态规划问题<1>积木游戏问题<2>决斗(判定性问题)<3>圆的最大多边形问题<4>统计单词个数问题<5>棋盘分割<6>日程安排问题<7>最小逼近问题(求出两数之比最接近某数/两数之和等于某数等等)<8>方块消除游戏(某区间可以连续消去求最大效益)<9>资源分配问题<10>数字三角形问题<11>漂亮的打印<12>邮局问题与构造答案<13>最高积木问题<14>两段连续和最大<15>2次幂和问题<16>N个数的最大M段子段和<17>交叉最大数问题4.判定性问题的dp(如判定整除、判定可达性等)<1>模K问题的dp<2>特殊的模K问题,求最大(最小)模K的数<3>变换数问题5.单调性优化的动态规划<1>1-SUM问题<2>2-SUM问题<3>序列划分问题(单调队列优化)6.剖分问题(多边形剖分/石子合并/圆的剖分/乘积最大)<1>凸多边形的三角剖分问题<2>乘积最大问题<3>多边形游戏(多边形边上是操作符,顶点有权值)<4>石子合并(N^3/N^2/NLogN各种优化)7.贪心的动态规划<1>最优装载问题<2>部分背包问题<3>乘船问题<4>贪心策略<5>双机调度问题Johnson算法8.状态dp<1>牛仔射击问题(博弈类)<2>哈密顿路径的状态dp<3>两支点天平平衡问题<4>一个有向图的最接近二部图9.树型dp<1>完美服务器问题(每个节点有3种状态)<2>小胖守皇宫问题<3>网络收费问题<4>树中漫游问题<5>树上的博弈<6>树的最大独立集问题<7>树的最大平衡值问题<8>构造树的最小环部分题目分类统计:网络流:最大流:1087 a plug for UNIX1149 PIGS1273 drainage ditches1274 the perfect stall1325 machine schedule1459 power network2239 selecting courses最小费用最大流:2195 going home?2400 supervisor, supervisee压缩存储的DP1038 bugs integrated inc1185 炮兵阵地2430 lazy cow最长公共子串(LCS):1080 human gene functions1159 palindrome1458 common subsequence2192 zipper凸包1113 wall2187 beauty contest1000 A+B Problem 送分题1001 Exponentiation 高精度1003 Hangover 送分题1004 Financial Management 送分题1005 I Think I Need a Houseboat 几何1006 Biorhythms 送分题1007 DNA Sorting 送分题1008 Maya Calendar 日期处理1010 STAMPS 搜索+DP1011 Sticks 搜索1012 Joseph 模拟/数学方法1014 Dividing 数论/DP?/组合数学->母函数? 1015 Jury Compromise DP1016 Numbers That Count 送分题1017 Packets 贪心1018 Communication System 贪心1019 Number Sequence 送分题1020 Anniversary Cake 搜索1023 The Fun Number System 数论1025 Department 模拟1026 Cipher 组合数学1027 The Same Game 模拟1028 Web Navigation 送分题1031 Fence 计算几何1034 The dog task 计算几何1037 A decorative fence DP/组合数学1039 Pipe 几何1042 Gone Fishing 贪心/DP1045 Bode Plot 送分题(用物理知识)1046 Color Me Less 送分题1047 Round and Round We Go 高精度1048 Follow My Logic 模拟1049 Microprocessor Simulation 模拟1050 To the Max DP1053 Set Me 送分题1054 The Troublesome Frog 搜索1060 Modular multiplication of polynomials 高精度1061 青蛙的约会数论1062 昂贵的聘礼DP1064 Cable master DP/二分查找1065 Wooden Sticks DP1067 取石子游戏博弈论1068 Parencodings 送分题1069 The Bermuda Triangle 搜索1070 Deformed Wheel 几何1071 Illusive Chase 送分题1072 Puzzle Out 搜索1073 The Willy Memorial Program 模拟1074 Parallel Expectations DP1075 University Entrance Examination 模拟1080 Human Gene Functions DP->LCS变形1082 Calendar Game 博弈论1084 Square Destroyer 搜索?1085 Triangle War 博弈论1086 Unscrambling Images 模拟?1087 A Plug for UNIX 图论->最大流1088 滑雪DFS/DP1090 Chain ->格雷码和二进制码的转换1091 跳蚤数论1092 Farmland 几何1093 Formatting Text DP1094 Sorting It All Out 图论->拓扑排序1095 Trees Made to Order 组合数学1096 Space Station Shielding 送分题1097 Roads Scholar 图论1098 Robots 模拟1099 Square Ice 送分题1100 Dreisam Equations 搜索1101 The Game 搜索->BFS1102 LC-Display 送分题1103 Maze 模拟1104 Robbery 递推1106 Transmitters 几何1107 W's Cipher 送分题1110 Double Vision 搜索1111 Image Perimeters 搜索1112 Team Them Up! DP1113 Wall 计算几何->convex hull1119 Start Up the Startup 送分题1120 A New Growth Industry 模拟1122 FDNY to the Rescue! 图论->Dijkstra1125 Stockbroker Grapevine 图论->Dijkstra1128 Frame Stacking 搜索1129 Channel Allocation 搜索(图的最大独立集)1131 Octal Fractions 高精度1135 Domino Effect 图论->Dijkstra1137 The New Villa 搜索->BFS1141 Brackets Sequence DP1142 Smith Numbers 搜索1143 Number Game 博弈论1147 Binary codes 构造1148 Utopia Divided 构造1149 PIGS 图论->网络流1151 Atlantis 计算几何->同等安置矩形的并的面积->离散化1152 An Easy Problem! 数论1157 LITTLE SHOP OF FLOWERS DP1158 TRAFFIC LIGHTS 图论->Dijkstra变形1159 Palindrome DP->LCS1160 Post Office DP1161 Walls 图论1162 Building with Blocks 搜索1163 The Triangle DP1170 Shopping Offers DP1177 Picture 计算几何->同等安置矩形的并的周长->线段树1179 Polygon DP1180 Batch Scheduling DP1182 食物链数据结构->并查集1183 反正切函数的应用搜索1184 聪明的打字员搜索1185 炮兵阵地DP->数据压缩1187 陨石的秘密DP(BalkanOI99 Par的拓展)1189 钉子和小球递推?1190 生日蛋糕搜索/DP1191 棋盘分割DP1192 最优连通子集图论->无负权回路的有向图的最长路->BellmanFord1193 内存分配模拟1194 HIDDEN CODES 搜索+DP1197 Depot 数据结构->Young Tableau1201 Intervals 贪心/图论->最长路->差分约束系统1202 Family 高精度1209 Calendar 日期处理1217 FOUR QUARTERS 递推1218 THE DRUNK JAILER 送分题1233 Street Crossing 搜索->BFS1245 Programmer, Rank Thyself 送分题1247 Magnificent Meatballs 送分题1248 Safecracker 搜索1250 Tanning Salon 送分题1251 Jungle Roads 图论->最小生成树1271 Nice Milk 计算几何1273 Drainage Ditches 图论->最大流1274 The Perfect Stall 图论->二分图的最大匹配1275 Cashier Employment 图论->差分约束系统->无负权回路的有向图的最长路->Bellman-Ford1280 Game 递推1281 MANAGER 模拟1286 Necklace of Beads 组合数学->Polya定理1288 Sly Number 数论->解模线性方程组1293 Duty Free Shop DP1298 The Hardest Problem Ever 送分题1316 Self Numbers 递推同Humble Number一样1322 Chocolate 递推/组合数学1323 Game Prediction 贪心1324 Holedox Moving BFS+压缩储存1325 Machine Schedule 图论->二分图的最大匹配1326 Mileage Bank 送分题1327 Moving Object Recognition 模拟?1328 Radar Installation 贪心(差分约束系统的特例)1338 Ugly Numbers 递推(有O(n)算法)1364 King 图论->无负权回路的有向图的最长路->BellmanFord 1370 Gossiping (数论->模线性方程有无解的判断)+(图论->DFS) 2184 Cow Exhibition DP2190 ISBN 送分题2191 Mersenne Composite Numbers 数论2192 Zipper DP->LCS变形2193 Lenny's Lucky Lotto Lists DP2194 Stacking Cylinders 几何2195 Going Home 图论->二分图的最大权匹配2196 Specialized Four-Digit Numbers 送分题2197 Jill's Tour Paths 图论->2199 Rate of Return 高精度2200 A Card Trick 模拟2210 Metric Time 日期处理2239 Selecting Courses 图论->二分图的最大匹配2243 Knight Moves 搜索->BFS2247 Humble Numbers 递推(最优O(n)算法)2253 Frogger 图论->Dijkstra变形(和1295是一样的)2254 Globetrotter 几何2261 France '98 递推2275 Flipping Pancake 构造2284 That Nice Euler Circuit 计算几何2289 Jamie's Contact Groups 图论->网络流?2291 Rotten Ropes 送分题2292 Optimal Keypad DP2299 Ultra-QuickSort 排序->归并排序2304 Combination Lock 送分题2309 BST 送分题2312 Battle City 搜索->BFS2314 POJ language 模拟2315 Football Game 几何2346 Lucky tickets 组合数学2351 Time Zones 时间处理2379 ACM Rank Table 模拟+排序2381 Random Gap 数论2385 Apple Catching DP(像NOI98“免费馅饼”)2388 Who's in the Middle 送分题(排序)2390 Bank Interest 送分题2395 Out of Hay 图论->Dijkstra变形2400 Supervisor, Supervisee 图论->二分图的最大权匹配?2403 Hay Points 送分题2409 Let it Bead 组合数学->Polya定理2416 Return of the Jedi 图论->2417 Discrete Logging 数论2418 Hardwood Species 二分查找2419 Forests 枚举2421 Constructing Roads 图论->最小生成树2423 The Parallel Challenge Ballgame 几何2424 Flo's Restaurant 数据结构->堆2425 A Chess Game 博弈论2426 Remainder BFS2430 Lazy Cows DP->数据压缩1375 Intervals 几何1379 Run Away 计算几何->1380 Equipment Box 几何1383 Labyrinth 图论->树的最长路1394 Railroad 图论->Dijkstra1395 Cog-Wheels 数学->解正系数的线性方程组1408 Fishnet 几何1411 Calling Extraterrestrial Intelligence Again 送分题1430 Binary Stirling Numbers 日期处理1431 Calendar of Maya 模拟1432 Decoding Morse Sequences DP1434 Fill the Cisterns! 计算几何->离散化/1445 Random number 数据结构->碓1447 Ambiguous Dates 日期处理1450 Gridland 图论(本来TSP问题是NP难的,但这个图比较特殊,由现成的构造方法)1458 Common Subsequence DP->LCS1459 Power Network 图论->最大流1462 Random Walk 模拟+解线性方程组1466 Girls and Boys 图论->n/a1469 COURSES 贪心1475 Pushing Boxes DP1476 Always On the Run 搜索->BFS1480 Optimal Programs 搜索->BFS1481 The Die Is Cast 送分题1482 It's not a Bug, It's a Feature! 搜索->BFS1483 Going in Circles on Alpha Centauri 模拟1484 Blowing Fuses 送分题1485 Fast Food DP(似乎就是ioi2000的postoffice)1486 Sorting Slides 图论->拓扑排序1505 Copying Books DP+二分查找1510 Hares and Foxes 数论1512 Keeps Going and Going and ... 模拟1513 Scheduling Lectures DP1514 Metal Cutting 几何1515 Street Directions 图论->把一个无向连通图改造成为有向强连通图1517 u Calculate e 送分题1518 Problem Bee 几何1519 Digital Roots 送分题(位数可能很大)1520 Scramble Sort 排序1547 Clay Bully 送分题1555 Polynomial Showdown 送分题(非常阴险)1563 The Snail 送分题1601 Pizza Anyone? 搜索1604 Just the Facts 送分题1605 Horse Shoe Scoring 几何1606 Jugs 数论/搜索1631 Bridging signals DP+二分查找1632 Vase collection 图论->最大完全图1633 Gladiators DP1634 Who's the boss? 排序1635 Subway tree systems 图论->不同表示法的二叉树判同1637 Sightseeing tour 图论->欧拉回路1638 A number game 博弈论1639 Picnic Planning 图论->1641 Rational Approximation 数论1646 Double Trouble 高精度1654 Area 几何1657 Distance on Chessboard 送分题1658 Eva's Problem 送分题1660 Princess FroG 构造1661 Help Jimmy DP1663 Number Steps 送分题1664 放苹果组合数学->递推1677 Girls' Day 送分题1688 Dolphin Pool 计算几何1690 (Your)((Term)((Project))) 送分题1691 Painting A Board 搜索/DP1692 Crossed Matchings DP1693 Counting Rectangles 几何1694 An Old Stone Game 博弈论?1695 Magazine Delivery 图论->1712 Flying Stars DP1713 Divide et unita 搜索1714 The Cave 搜索/DP1717 Dominoes DP1718 River Crossing DP1719 Shooting Contest 贪心1729 Jack and Jill 图论->1730 Perfect Pth Powers 数论1732 Phone numbers DP1734 Sightseeing trip 图论->Euler回路1738 An old Stone Game 博弈论?1741 Tree 博弈论?1745 Divisibility DP1751 Highways 图论->1752 Advertisement 贪心/图论->差分约束系统1753 Flip Game 搜索->BFS1755 Triathlon 计算几何?1770 Special Experiment 树形DP1771 Elevator Stopping Plan DP1772 New Go Game 构造?1773 Outernet 模拟1774 Fold Paper Strips 几何1775 Sum of Factorials 送分题1776 Task Sequences DP1777 Vivian's Problem 数论1870 Bee Breeding 送分题1871 Bullet Hole 几何1872 A Dicey Problem BFS1873 The Fortified Forest 几何+回溯1874 Trade on V erweggistan DP1875 Robot 几何1876 The Letter Carrier's Rounds 模拟1877 Flooded! 数据结构->堆1879 Tempus et mobilius Time and motion 模拟+组合数学->Polya定理1882 Stamps 搜索+DP1883 Theseus and the Minotaur 模拟1887 Testing the CATCHER DP1889 Package Pricing DP1893 Monitoring Wheelchair Patients 模拟+几何1915 Knight Moves 搜索->BFS1916 Rat Attack 数据结构->?1936 All in All DP?1946 Cow Cycling DP1947 Rebuilding Roads 二分1985 Cow Marathon 图论->有向无环图的最长路1995 Raising Modulo Numbers 数论->大数的幂求余2049 Finding Nemo 图论->最短路2050 Searching the Web 模拟(需要高效实现)2051 Argus 送分题(最好用堆,不用也可以过)2054 Color a Tree 贪心2061 Pseudo-random Numbers 数论2080 Calendar 日期处理2082 Terrible Sets 分治/2083 Fractal 递归2084 Game of Connections 递推(不必高精度)2105 IP Address 送分题2115 C Looooops 数论->解模线性方程2136 Vertical Histogram 送分题2165 Gunman 计算几何2179 Inlay Cutters 枚举2181 Jumping Cows 递推2182 Lost Cows ->线段树/发一个按类型排序的版本1370 Gossiping (数论->模线性方程有无解的判断)+(图论->DFS)1090 Chain ->格雷码和二进制码的转换2182 Lost Cows ->线段树/2426 Remainder BFS1872 A Dicey Problem BFS1324 Holedox Moving BFS+压缩储存1088 滑雪 DFS/DP1015 Jury Compromise DP1050 To the Max DP1062 昂贵的聘礼 DP1065 Wooden Sticks DP1074 Parallel Expectations DP1093 Formatting Text DP1112 Team Them Up! DP1141 Brackets Sequence DP1157 LITTLE SHOP OF FLOWERS DP1160 Post Office DP1163 The Triangle DP1170 Shopping Offers DP1179 Polygon DP1180 Batch Scheduling DP1191 棋盘分割 DP1293 Duty Free Shop DP2184 Cow Exhibition DP2193 Lenny's Lucky Lotto Lists DP2292 Optimal Keypad DP1432 Decoding Morse Sequences DP1475 Pushing Boxes DP1513 Scheduling Lectures DP1633 Gladiators DP1661 Help Jimmy DP1692 Crossed Matchings DP1712 Flying Stars DP1717 Dominoes DP1718 River Crossing DP1732 Phone numbers DP1745 Divisibility DP1771 Elevator Stopping Plan DP1776 Task Sequences DP1874 Trade on Verweggistan DP1887 Testing the CATCHER DP1889 Package Pricing DP1946 Cow Cycling DP1187 陨石的秘密 DP(BalkanOI99 Par的拓展)1485 Fast Food DP(似乎就是ioi2000的postoffice) 2385 Apple Catching DP(像NOI98“免费馅饼”) 1064 Cable master DP/二分查找1037 A decorative fence DP/组合数学1936 All in All DP?1505 Copying Books DP+二分查找1631 Bridging signals DP+二分查找1159 Palindrome DP->LCS1458 Common Subsequence DP->LCS1080 Human Gene Functions DP->LCS变形2192 Zipper DP->LCS变形1185 炮兵阵地 DP->数据压缩2430 Lazy Cows DP->数据压缩1067 取石子游戏博弈论1082 Calendar Game 博弈论1085 Triangle War 博弈论1143 Number Game 博弈论2311 Cutting Game 博弈论2425 A Chess Game 博弈论1638 A number game 博弈论1694 An Old Stone Game 博弈论?1738 An old Stone Game 博弈论?1741 Tree 博弈论?2083 Fractal 递归1104 Robbery 递推1217 FOUR QUARTERS 递推1280 Game 递推2261 France '98 递推2181 Jumping Cows 递推1316 Self Numbers 递推同Humble Number一样2084 Game of Connections 递推(不必高精度)1338 Ugly Numbers 递推(有O(n)算法)2247 Humble Numbers 递推(最优O(n)算法)1322 Chocolate 递推/组合数学1189 钉子和小球递推?1947 Rebuilding Roads 二分2418 Hardwood Species 二分查找2082 Terrible Sets 分治/1001 Exponentiation 高精度1047 Round and Round We Go 高精度1060 Modular multiplication of polynomials 高精度1131 Octal Fractions 高精度1202 Family 高精度2199 Rate of Return 高精度1646 Double Trouble 高精度1147 Binary codes 构造1148 Utopia Divided 构造2275 Flipping Pancake 构造1660 Princess FroG 构造1772 New Go Game 构造?1005 I Think I Need a Houseboat 几何1039 Pipe 几何1070 Deformed Wheel 几何1092 Farmland 几何1106 Transmitters 几何2194 Stacking Cylinders 几何2254 Globetrotter 几何2315 Football Game 几何2423 The Parallel Challenge Ballgame 几何1375 Intervals 几何1380 Equipment Box 几何1408 Fishnet 几何1514 Metal Cutting 几何1518 Problem Bee 几何1605 Horse Shoe Scoring 几何1654 Area 几何1693 Counting Rectangles 几何1774 Fold Paper Strips 几何1871 Bullet Hole 几何1875 Robot 几何1873 The Fortified Forest 几何+回溯1031 Fence 计算几何1034 The dog task 计算几何1271 Nice Milk 计算几何2284 That Nice Euler Circuit 计算几何1688 Dolphin Pool 计算几何2165 Gunman 计算几何1755 Triathlon 计算几何?1379 Run Away 计算几何->1113 Wall 计算几何->convex hull1434 Fill the Cisterns! 计算几何->离散化/1151 Atlantis 计算几何->同等安置矩形的并的面积->离散化1177 Picture 计算几何->同等安置矩形的并的周长->线段树2419 Forests 枚举2179 Inlay Cutters 枚举1025 Department 模拟1027 The Same Game 模拟1048 Follow My Logic 模拟1049 Microprocessor Simulation 模拟1073 The Willy Memorial Program 模拟1075 University Entrance Examination 模拟1098 Robots 模拟1103 Maze 模拟1120 A New Growth Industry 模拟1193 内存分配模拟1281 MANAGER 模拟2200 A Card Trick 模拟2314 POJ language 模拟1431 Calendar of Maya 模拟1483 Going in Circles on Alpha Centauri 模拟1512 Keeps Going and Going and ... 模拟1773 Outernet 模拟1876 The Letter Carrier's Rounds 模拟1883 Theseus and the Minotaur 模拟2050 Searching the Web 模拟(需要高效实现)1012 Joseph 模拟/数学方法1086 Unscrambling Images 模拟?1327 Moving Object Recognition 模拟?1893 Monitoring Wheelchair Patients 模拟+几何1462 Random Walk 模拟+解线性方程组2379 ACM Rank Table 模拟+排序1879 Tempus et mobilius Time and motion 模拟+组合数学->Polya定理1520 Scramble Sort 排序1634 Who's the boss? 排序2299 Ultra-QuickSort 排序->归并排序1008 Maya Calendar 日期处理1209 Calendar 日期处理2210 Metric Time 日期处理1430 Binary Stirling Numbers 日期处理1447 Ambiguous Dates 日期处理2080 Calendar 日期处理2351 Time Zones 时间处理1770 Special Experiment 树形DP1916 Rat Attack 数据结构->?1197 Depot 数据结构->Young Tableau1182 食物链数据结构->并查集2424 Flo's Restaurant 数据结构->堆1877 Flooded! 数据结构->堆1445 Random number 数据结构->碓1023 The Fun Number System 数论1061 青蛙的约会数论1091 跳蚤数论1152 An Easy Problem! 数论2191 Mersenne Composite Numbers 数论2381 Random Gap 数论2417 Discrete Logging 数论1510 Hares and Foxes 数论1641 Rational Approximation 数论1730 Perfect Pth Powers 数论1777 Vivian's Problem 数论2061 Pseudo-random Numbers 数论1014 Dividing 数论/DP?/组合数学->母函数?1606 Jugs 数论/搜索1995 Raising Modulo Numbers 数论->大数的幂求余2115 C Looooops 数论->解模线性方程1288 Sly Number 数论->解模线性方程组1395 Cog-Wheels 数学->解正系数的线性方程组1000 A+B Problem 送分题1003 Hangover 送分题1004 Financial Management 送分题1006 Biorhythms 送分题1007 DNA Sorting 送分题1016 Numbers That Count 送分题1019 Number Sequence 送分题1028 Web Navigation 送分题1046 Color Me Less 送分题1053 Set Me 送分题1068 Parencodings 送分题1071 Illusive Chase 送分题1096 Space Station Shielding 送分题1099 Square Ice 送分题1102 LC-Display 送分题1107 W's Cipher 送分题1119 Start Up the Startup 送分题1218 THE DRUNK JAILER 送分题1245 Programmer, Rank Thyself 送分题1247 Magnificent Meatballs 送分题1250 Tanning Salon 送分题1298 The Hardest Problem Ever 送分题1326 Mileage Bank 送分题2190 ISBN 送分题2196 Specialized Four-Digit Numbers 送分题2291 Rotten Ropes 送分题2304 Combination Lock 送分题2309 BST 送分题2390 Bank Interest 送分题2403 Hay Points 送分题1411 Calling Extraterrestrial Intelligence Again 送分题1481 The Die Is Cast 送分题1484 Blowing Fuses 送分题1517 u Calculate e 送分题1547 Clay Bully 送分题1563 The Snail 送分题1604 Just the Facts 送分题1657 Distance on Chessboard 送分题1658 Eva's Problem 送分题1663 Number Steps 送分题1677 Girls' Day 送分题1690 (Your)((Term)((Project))) 送分题1775 Sum of Factorials 送分题1870 Bee Breeding 送分题2105 IP Address 送分题2136 Vertical Histogram 送分题1555 Polynomial Showdown 送分题(非常阴险) 2388 Who's in the Middle 送分题(排序)1519 Digital Roots 送分题(位数可能很大)1045 Bode Plot 送分题(用物理知识)2051 Argus 送分题(最好用堆,不用也可以过) 1011 Sticks 搜索1020 Anniversary Cake 搜索1054 The Troublesome Frog 搜索1069 The Bermuda Triangle 搜索1072 Puzzle Out 搜索1100 Dreisam Equations 搜索1110 Double Vision 搜索1111 Image Perimeters 搜索1128 Frame Stacking 搜索1142 Smith Numbers 搜索1162 Building with Blocks 搜索1183 反正切函数的应用搜索1184 聪明的打字员搜索1248 Safecracker 搜索1601 Pizza Anyone? 搜索1713 Divide et unita 搜索1129 Channel Allocation 搜索(图的最大独立集)1190 生日蛋糕搜索/DP1691 Painting A Board 搜索/DP1714 The Cave 搜索/DP1084 Square Destroyer 搜索?1010 STAMPS 搜索+DP1194 HIDDEN CODES 搜索+DP1882 Stamps 搜索+DP1101 The Game 搜索->BFS1137 The New Villa 搜索->BFS1233 Street Crossing 搜索->BFS2243 Knight Moves 搜索->BFS2312 Battle City 搜索->BFS1476 Always On the Run 搜索->BFS1480 Optimal Programs 搜索->BFS1482 It's not a Bug, It's a Feature! 搜索->BFS1753 Flip Game 搜索->BFS1915 Knight Moves 搜索->BFS1017 Packets 贪心1018 Communication System 贪心1323 Game Prediction 贪心1463 Strategic game 贪心1469 COURSES 贪心1719 Shooting Contest 贪心2054 Color a Tree 贪心1328 Radar Installation 贪心(差分约束系统的特例)1042 Gone Fishing 贪心/DP1752 Advertisement 贪心/图论->差分约束系统1201 Intervals 贪心/图论->最长路->差分约束系统1097 Roads Scholar 图论1161 Walls 图论1450 Gridland 图论(本来TSP问题是NP难的,但这个图比较特殊,由现成的构造方法)2197 Jill's Tour Paths 图论->2416 Return of the Jedi 图论->1639 Picnic Planning 图论->1695 Magazine Delivery 图论->1729 Jack and Jill 图论->1751 Highways 图论->1122 FDNY to the Rescue! 图论->Dijkstra1125 Stockbroker Grapevine 图论->Dijkstra1135 Domino Effect 图论->Dijkstra1394 Railroad 图论->Dijkstra1158 TRAFFIC LIGHTS 图论->Dijkstra变形2395 Out of Hay 图论->Dijkstra变形2253 Frogger 图论->Dijkstra变形(和1295是一样的)1734 Sightseeing trip 图论->Euler回路1466 Girls and Boys 图论->n/a1515 Street Directions 图论->把一个无向连通图改造成为有向强连通图1635 Subway tree systems 图论->不同表示法的二叉树判同1275 Cashier Employment 图论->差分约束系统->无负权回路的有向图的最长路->Bellman-Ford1274 The Perfect Stall 图论->二分图的最大匹配1325 Machine Schedule 图论->二分图的最大匹配2239 Selecting Courses 图论->二分图的最大匹配2195 Going Home 图论->二分图的最大权匹配2400 Supervisor, Supervisee 图论->二分图的最大权匹配? 1637 Sightseeing tour 图论->欧拉回路1383 Labyrinth 图论->树的最长路1094 Sorting It All Out 图论->拓扑排序1486 Sorting Slides 图论->拓扑排序1149 PIGS 图论->网络流2289 Jamie's Contact Groups 图论->网络流?1192 最优连通子集图论->无负权回路的有向图的最长路->BellmanFord1364 King 图论->无负权回路的有向图的最长路->BellmanFord 1985 Cow Marathon 图论->有向无环图的最长路1087 A Plug for UNIX 图论->最大流1273 Drainage Ditches 图论->最大流1459 Power Network 图论->最大流1632 Vase collection 图论->最大完全图2049 Finding Nemo 图论->最短路1251 Jungle Roads 图论->最小生成树2421 Constructing Roads 图论->最小生成树1026 Cipher 组合数学1095 Trees Made to Order 组合数学2346 Lucky tickets 组合数学1286 Necklace of Beads 组合数学->Polya定理2409 Let it Bead 组合数学->Polya定理1664 放苹果组合数学->递推。

C-POJ习题

C-POJ习题
计算机学院学生会生活部 6
C 语言 POJ 习题答案
◆T0502 #include<stdio.h> int main() { int a,b; float c; scanf("%d%d",&a,&b); c=a+b/100.00; if(c<=1.20) printf("%d 月%d 日是摩羯座\n",a,b); else if(c<=2.20) printf("%d 月%d 日为宝瓶座\n",a,b); else if(c<=3.20) printf("%d 月%d 日为双鱼座\n",a,b); else if(c<=4.20) printf("%d 月%d 日为白羊座\n",a,b); else if(c<=5.20) printf("%d 月%d 日为金牛座\n",a,b); else if(c<=6.20) printf("%d 月%d 日为双子座\n",a,b); else if(c<=7.22) printf("%d 月%d 日为巨蟹座\n",a,b); else if(c<=8.22) printf("%d 月%d 日为狮子座\n",a,b); else if(c<=9.22) printf("%d 月%d 日为处女座\n",a,b); else if(c<=10.22) printf("%d 月%d 日为天秤座\n",a,b); else if(c<=11.22) printf("%d 月%d 日为天蝎座\n",a,b); else if(c<=12.22) printf("%d 月%d 日为人马座\n",a,b); else printf("%d 月%d 日为摩羯座\n",a,b); return 0; } ◆T0505 #include<stdio.h> #include<math.h> int main() { int h,m,a,b,c; scanf("%d:%d",&h,&m); a=30*h+m/2; b=6*m; c=abs(b-a); if (c>180) c=360-c; printf("c=%d\n",c); return 0; } ◆SXD02 #include<stdio.h> int main() { int i; for(i=100;i<=200;i++) {

POJ部分水题代码(C++)(三)

POJ部分水题代码(C++)(三)

// POJ2709 #include<iostream> #include<iomanip> using namespace std; int main() { double n,i,k; double a,b; cin>>n; b=0; for(i=n;i>=1;i=i-1) { { a=a*k; } a=1/a; b=b+a; a=1; for(k=i;k>=1;k=k-1)
for (int j=0; j<n; j++) { if ((student[j].final>80)&&(student[j].theory>0)) { student[j].amount += 8000; total += 8000; } if ((student[j].final>85)&&(student[j].others>80)) { student[j].amount += 4000; total += 4000; } if ((student[j].final>90)) { student[j].amount += 2000; total += 2000; } if ((student[j].final>85)&&((student[j].west=='Y')||(student[j].west=='y'))) { student[j].amount += 1000; total += 1000; } if ((student[j].others>80)&&((student[j].ganbu=='Y')||(student[j].ganbu=='y'))) { student[j].amount += 850; total += 850; } } for (k=0; k<n; k++) { if (money<=student[k].amount) money = student[k].amount; } if (money!=0) { for (k=0; k<n; k++) { if (money==student[k].amount) { cout << student[k].name << endl; break; }

完整版本的 poj 题目分类

完整版本的 poj 题目分类

完整版本的poj 题目分类DP:1011 NTA 简单题1013 Great Equipment 简单题1024 Calendar Game 简单题1027 Human Gene Functions 简单题1037 Gridland 简单题1052 Algernon s Noxious Emissions 简单题1409 Communication System 简单题,但是很容易看错~~~1425 Crossed Matchings 简单题1438 Asteroids! 简单题1459 String Distance and Transform Process 简单题1462 Team Them Up! 简单题1556 Heroes Of Might And Magic 简单题,不过背景蛮有意思的……1520 Duty Free Shop 简单题1524 Supermarket 简单题1301 The New Villa 简单题1303 Jury Compromise 其实不是很难,但是很容易错,555……1345 Best Deal 简单题,但是也很容易错……555……1360 Radar Installation 简单题1396 The Umbrella Problem: 2054 简单题1058 Currency Exchange 简单题1076 Gene Assembly 简单题1092 Arbitrage 简单题1093 Monkey and Banana 简单题1094 Matrix Chain Multiplication 简单题1536 Labyrinth 简单题1100 Mondriaan s Dream 简单题,DP可以过,不过据说有复杂的组合公式1103 Hike on a Graph 简单题1134 Strategic Game 简单题1147 Formatting Text 简单题1148 The Game 简单题1161 Gone Fishing 简单题1180 Self Numbers 简单题1192 It s not a Bug, It s a Feature! 简单题1196 Fast Food 简单题1107 FatMouse and Cheese 简单题,不过题目描述有些混乱1136 Multiple 简单题,BFS1276 Optimal Array Multiplication Sequence 简单题1255 The Path 简单题1250 Always On the Run 简单题1213 Lumber Cutting 简单题1206 Win the Bonus 简单题1479 Dweep 无聊题1587 UP 100 无聊题,DP应该可以……但是太烦了……没做……1066 Square Ice 无聊题,目前已知的O(nlogn)算法要用***L……您有没有简单点的O(nlogn)的算法?1245 Triangles 无聊题1022 Parallel Expectations 经典题,想了n久,最后发现可以DP,相当好的一道题1499 Increasing Sequences 经典题{}1039 Number Game 没有完美解决的题,感觉可以直接以所有剩下的数作为状态DP,但是缺乏证明……1227 Free Candies SRbGa的经典题,我看了oibh上的解题报告才做出来的……:( 1234 Chopsticks SRbGa的经典题……图论:1525 Air Raid 简单题,最小路径覆盖1500 Pre-Post-erous! 简单题1501 Knockout Tournament 简单题1508 Intervals 对您来说应该是简单题,但我想了n久……:(,差分限制系统1333 Galactic Import 简单题1304 Tin Cutter 简单题,但是似乎有空间复杂度为O(n)的算法1310 Robot 简单题1311 Network 简单题1344 A Mazing Problem 简单题1395 Door Man 简单题,欧拉回路1372 Networking 简单题1406 Jungle Roads 简单题1053 FDNY to the Rescue! 简单题1055 Oh, Those Achin Feet 不错的简单题1059 What s In a Name 简单题1064 Roads Scholar 简单题1082 Stockbroker Grapevine 简单题1085 Alien Security 简单题,我觉得我当时的算法好巧妙:)1097 Code the Tree 简单题1060 Sorting It All Out 简单题,但是规模要是大些的话……1105 FatMouse s Tour 简单题1119 SPF 简单题1127 Roman Forts 简单题1140 Courses 简单题1157 A Plug for UNIX 蛮不错的简单题1203 Swordfish 简单题1221 Risk 简单题,最短路1197 Sorting Slides 简单题,匹配1268 Is It A Tree? 不错的题,图论1273 It s Ir-Resist-Able! 简单题,图论1298 Domino Effect 简单题,最长路1260 King 简单题,差分限制系统……1291 MPI Maelstrom 不错的题,最长路1266 Gossiping 简单题1285 Shipping Routes 无聊题,最短路1313 Gears on a Board 无聊题1502 Plugged In 无聊题,匹配应该可以,但是太烦了,没做……1568 WishingBone s Room Plan 无聊题,最大最小匹配,不过容易看错题~~~~~~ 1077 Genetic Combinations 无聊题,匹配1364 Machine Schedule 背诵题……匹配……1137 Girls and Boys 背诵题,匹配……1023 University Entrace Examination 经典题,但是和1576重复1576 Marriage is Stable 经典题,感人的背景,经典的算法……1249 Pushing Boxes 经典题,某人的论文写过,求割点和块+BFS可以在O(面积)的时间内做出来,但是这题似乎已经比较老了1141 Closest Common Ancestors 没有完美解决,最简单的算法就能过,但要是规模大了……1084 Channel Allocation 尚未完美解决,我用搜索过的,不过是不是有更好的算法呢……?1231 Mysterious Mountain SRbGa的经典题……1232 Adventure of Super Mario SRbGa的经典题……数学:1007 Numerical Summation of a Series 简单题,还是蛮有意思的1045 HangOver 简单题1049 I Think I Need a Houseboat 简单题1028 Flip and Shift 简单题,可以DP/BFS/……,但是实际上有数学方法可以直接判断出来1026 Modular multiplication of polynomials 简单题,感觉有比较简单的好算法,但想不出来:(1307 Packets 简单题,不过也蛮经典的……1312 Prime Cuts 简单题1334 Basically Speaking 简单题1337 Pi 简单题1342 Word Index 简单题1349 Four Quarters 简单题1350 The Drunk Jailer 简单题1352 Number Base Conversion 简单题1353 Unimodal Palindromic Decompositions 规模不大,所以是简单题……1354 Extended Lights Out 简单题1362 Game Prediction 简单题1365 Mileage Bank 简单题1382 A Simple Task 简单题1383 Binary Numbers 简单题1403 Safecracker 简单题1408 The Fun Number System 简单题1486 Color the Tree 简单题1487 Playing Cards 简单题1489 2^x mod n = 1 简单题,应该有好算法,不过枚举就可以过……1503 One Person "The Price is Right" 简单题,POI Eggs的翻版1512 Water Treatment Plants 简单题,组合计数1526 Big Number 简单题,不过O(1)和O(n)还是有区别的:)1529 Enigmatic Travel 简单题,不过个人感觉题目描述很令人费解1530 Find The Multiple 简单题1537 Playing with a Calculator 简单题1577 GCD & LCM 简单题,分区联赛的题……1005 Jugs 简单题1543 Stripies 简单题1569 Partial Sums 简单题1062 Trees Made to Order 简单题1070 Bode Plot 简单题1073 Round and Round We Go 简单题,142857,我喜欢^_^1078 Palindrom Numbers 简单题1086 Octal Fractions 简单题1199 Point of Intersection 简单题1104 Leaps Tall Buildings 简单题1110 Dick and Jane 简单题1115 Digital Roots 简单题1113 u Calculate e 简单题1152 A Mathematical Curiosity 简单题1154 Niven Numbers 简单题1160 Biorhythms 简单题1163 The Staircases 简单题1177 K-Magic Number 简单题1184 Counterfeit Dollar 简单题1182 Keeps Going and Going and ... 简单题,我喜欢:)1284 Perfection 简单题1272 Numerically Speaking 简单题1269 Coconuts, Revisited 简单题1247 There s Treasure Everywhere! 简单题1241 Geometry Made Simple 简单题1202 Divide and Count 简单题1216 Deck 简单题1218 Ratio 简单题1261 Prime Land 简单题1212 Mountain Landscape 无聊题1410 Number Sequence 无聊题1401 Hilbert Curve Intersections 无聊题1331 Perfect Cubes 无聊题1322 Random Number 无聊题1535 Lucky Ticket 无聊题1539 Lot 无聊题1363 Chocolate 经典题……1366 Cash Machine 经典题!强烈推荐!1149 Dividing up 经典题,应该可以用1366的方法做,但似乎可以利用问题的特殊性用贪心+DP在O(1)的时间内做出来1222 Just the Facts 经典题,没有完美解决,我的做法是O(logn^2)的,据说可能有O(logn)的做法,但我没想到:(1475 Ranklist 没有完美解决,不知道您有没有好方法……1572 Bracelet ~~~题义不明,感觉可能是判定欧拉回路的存在性,但是过不去,555……1133 Smith Numbers 没有完美解决,数学1080 Direct Subtraction 尚未解决,我过的程序是错的,想和您讨论~~~1229 Gift?! SRbGa的经典题……1238 Guess the Number SRbGa的经典题……1239 Hanoi Tower Troubles Again! SRbGa的经典题……字符串处理:1050 Start Up the Startup 简单题1315 Excuses, Excuses! 简单题1151 Word Reversal 简单题,好像是什么Practice的……1170 String Matching 简单题1174 Skip Letter Code 不错的简单题1175 Word Process Machine 简单题1181 Word Amalgamation 简单题1038 T9 无聊题,单词树1330 DNA Translation 无聊题1335 Letter Sequence Analysis 无聊题1099 HTML 无聊题1243 URLs 无聊题1540 Censored! 经典题!强烈推荐!1511 Word Puzzles 没有完美解决的题,可以用后缀树……但是没多大意义……而且我通过的程序是错的……搜索:1002 Fire Net 简单题,CEOI2002的Guard的缩小版,搜索就可以1003 Crashing Balloon 简单题,很faint的题目,想了半天,最后发现最简单的搜索就能过1004 Anagrams by Stack 简单题,同样faint1320 DEL Command 简单题1496 Best Fit 简单题1179 Finding Rectangles 简单题1190 Optimal Programs 简单题1217 Eight 简单题1204 Additive equations 简单题1219 Pizza Anyone? 简单题1036 Enigma 2 无聊题,终于耐心读完题目后发现是简单的搜索+模拟……faint……建议不要看……1089 Lotto 无聊题1054 For the Porsche 无聊题1302 Ships ……题1031 Square Destroyer 变态题,:(:(:(:(,狂剪枝才过的……1297 Hexagon 变态题,标准解法是搜索……1008 Gnome Tetravex 经典题,个人感觉是很不错的卡时搜索,不过似乎IOI不会出这种题型……1380 Microfiches 经典题!强烈推荐!1252 Island of Logic 经典题,不过也够老了……1237 Fans and Gems SRbGa的经典题,变态,但是很有趣:)模拟:1051 A New Growth Industry 简单题1300 Border 简单题1326 M*A*S*H 简单题1494 Climbing Worm 简单题1072 Microprocessor Simulation 简单题1098 Simple Computers 简单题1056 The Worm Turns 简单题1195 Blowing Fuses 简单题1189 Numbers That Count 简单题1144 Robbery 简单题1153 Tournament Seeding 简单题,但是直接计算好像不行,得模拟……:(1167 Trees on the Level 简单题1200 Mining 简单题1278 Pseudo-Random Numbers 简单题1257 Parking Lot 简单题1270 Nonstop Travel 简单题1207 The Knight, the Princess, and the Dragons 无聊题1169 Square Cipher 无聊题1176 Die and Chessboard 无聊题1178 Booklet Printing 无聊题1009 Enigma 无聊题,但是很容易错……:(1012 Mainframe 无聊题,但是很容易错……:(1324 Unix ls 无聊题,输出格式没说清楚~~~~~~~1336 Mark-up 无聊题1277 Transferable V oting 无聊题1279 Cowculations 无聊题1281 Hi-Q 无聊题1282 Call Forwarding 无聊题1065 Robots 变态题,太复杂啦~~~~~~~~~~~1208 Roll the Die! 变态题1388 Exchanges 经典题!强烈推荐!1236 Eat or Not to Eat? SRbGa的经典题……模拟几何:1575 Koch Curve 简单题1010 Area 简单题1565 Input 简单题1081 Points Within 简单题1165 Laser Lines 简单题,但是算法能否再改进呢……?1248 Video Surveillance 简单题,李彭煦的论文中写到过,好像是某年CTSC的……1299 Pendulum 简单题,我蛮喜欢的:)1090 The Circumference of the Circle 无聊题1271 Doing Windows 无聊题1280 Intersecting Lines 无聊题1296 Stars 经典变态题……1030 Farmland 变态题……现在我都为自己当时居然能做出来感到不可思议……1041 Transmitters 变态题……好烦人……现在绝对没有信心再做一遍了……1158 Treasure Hunt 经典题,zig教会我的……1139 Rectangles 没有完美解决其它:1006 Do the Untwist 简单题1014 Operand 简单题1016 Parencodings 简单题1042 W s Cipher 简单题1047 Image Perimeters 简单题1514 Fake Tickets 简单题1029 Moving Tables 简单题,好像是线段树的经典题目之一,但是这题规模比较小,所以不必用。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

{ if (j>=0) inresult[l] += add1[j]-'0'; if (k>=0) inresult[l] += add2[k]-'0'; } if (deresult[0]==1) // 从小数到整数的进位 inresult[0]++; for (j=0; j<l; j++) if (inresult[j]>9) { inresult[j+1] += 1; inresult[j] -= 10; } while (inresult[j+1]) j++; // 保证 j 处于整数的最高位 l = j; // l 记载了整数的位数 以后不变 for (j=l-1; j>=0; j--) printf("%d",inresult[j]); printf("."); for(j=m; deresult[j]==0; j--); // 空循环 去掉最后的 0 m=j; for (j=1; j<=m; j++) printf("%d",deresult[j]); printf("\n"); } return 0; }
/********************** author KINGRAIN@EECS_PKU time April 4,2010 computerroom poj2737 大整数除法 ***********************/ #include <iostream> #include <cstring> using namespace std; const int LENGTH = 110; char num1[LENGTH]={0},num2[LENGTH]={0},temp[LENGTH]={0},sum[LENGTH]={0}; int Divide(int); int length1=0,length2=0; int main() { int n=0,i=0,t=0,j=0,delta=0; cin >> t; for (i=0; i<t; i++) { memset(sum,0,sizeof(sum)); cin >> num1 >> num2; length1 = strlen(num1); length2 = strlen(num2); _strrev(num2), _strrev(num1); // 将两个数字都逆 序 delta = length1 - length2; if (delta<0) { printf("0\n"); continue; } for (j=0; delta>=0;j++) { sum[j] = '0'+ Divide(delta--); } sum[j] = 0; char *ptr=sum; for (j=0; ptr[j]=='0'; j++); // 空循环去除前导零 cout << ptr+j << endl; } return 0;
int i=0; for (; i<length; i++) { if (temp[i]>10) { temp[i+1] += temp[i]/10; temp[i] %= 10; } } while (temp[i]>0) { if (temp[i]>10) { temp[i+1] += temp[i]/10; temp[i] %= 10; } i++; } for (i=MAX-1; temp[i]==0; i--); length = i+1; memcpy(result,temp,sizeof(result)); } bool COMPARE(int r[],int b[]) { for (int i=MAX-1; i>=0; i--) if (r[i]>b[i]) return 1; else if (r[i]<b[i]) return 0; }
struct MONKEY { int num; MONKEY * next; }; int main() { int n,m; while (cin >> n >> m) { if (n==0) break; if (m==1) // 针对 m==1 直接 可以知道答案 是 n { printf("%d\n",n); continue; } MONKEY *head=0,*current=0; for (int i=0; i<n; i++) // 建立循环链表 { if (head==0) { current = new MONKEY; current->num = 1; head = current; current->next = current; // 防止自己循环但 实际上 测试数据应该不会有 n==1 } else { current->next = new MONKEY; current = current->next; current->num = i+1; current->next = head; // 成环 } } current = head; MONKEY *temp=0; int i=1; while (current->next!=current) {
/********************** author KINGRAIN@EECS_PKU time Mar.20,2010 dorm poj2738 浮点数加法
***********************/ #include <iostream> #include <cstring> using namespace std; int main() { char add1[200]={0}, add2[200]={0}; // add1 & add2 分别是两个加数 char integer1[100]={0},integer2[100]={0}; int n=0,i=0,j=0,k=0,l=0,m=0,length1=0,length2=0,pointpos1=0,pointpos2=0; // pointpos 记录小数点的位置 length 记录加数的长度 int inresult[100]={0},deresult[100]={0}; // integer 记录整数部分 decimal 记录小数部分 cin >> n; for (i=0; i<n; i++) { cin >> add1 >> add2; memset(inresult,0,sizeof(inresult)); memset(deresult,0,sizeof(deresult)); length1 = strlen(add1); length2 = strlen(add2); for (j=0; add1[j]!='.'; j++); // 空循环 确定小数点位置 pointpos1 = j; for (j=0; add2[j]!='.'; j++); // 空循环 确定小数点位置 pointpos2 = j; for (m=1,j=pointpos1+1,k=pointpos2+1; add1[j]||add2[k]; j++,k++,m++) // 小数部分相加 { if (j<length1) deresult[m] += add1[j]-'0'; if (k<length2) deresult[m] += add2[k]-'0'; } // 此时 m-1 就是小数的位数 for (j=m-1; j>0; j--) if (deresult[j]>9) { deresult[j-1]++; deresult[j] -= 10; } for (l=0,j=pointpos1-1,k=pointpos2-1; j>=0||k>=0; j--,k--,l++)
/********************** author KINGRAIN@EECS_PKU time May 17,2010 dorm poj2739 计算对数 ***********************/ #include <iostream> #include <cstring> #include <memory> using namespace std;
int main() { int n=0,i=0,j=0,k=0,m=0; cin >> n; for (i=0; i<n; i++) { cin >> A >> B; length1 = strlen(A); for (k=length1-1; k>=0; k--) a[length1-k-1] = A[k] - '0'; length2 = strlen(B); for (k=length2-1; k>=0; k--) b[length2-k-1] = B[k] - '0'; length = length1; memcpy(result,a,sizeof(a)); for (j=0; j<21; j++) { if (C j << endl; break; } Caculate(); } memset(a,0,MAX*sizeof(int)); memset(b,0,MAX*sizeof(int)); memset(result,0,MAX*sizeof(int)); } return 0; } void Caculate() { int temp[MAX]={0}; for (int i=0; i<length; i++) for (int j=0; j<length1; j++) temp[i+j] += result[i] * a[j];
相关文档
最新文档