月度归档:2016年03月

Code hunt题解(3)

04.01

04.02

04.03

04.04

04.05

写if语句多的话不给三星QAQ

04.06

04.07

04.08

04.09

04.10

04.11

04.12

05.01

还是如果if判断条件多的话,不给三星,所以比赛的时候注意一下。

 

05.02

 

05.03

直角三角形,试了多组数据才看出来。

05.04

05.05

 

 

poj 1256 Anagram(STL水题)

Description

You are to write a program that has to generate all possible words from a given set of letters.
Example: Given the word “abc”, your program should – by exploring all different combination of the three letters – output the words “abc”, “acb”, “bac”, “bca”, “cab” and “cba”.
In the word taken from the input file, some letters may appear more than once. For a given word, your program should not produce the same word more than once, and the words should be output in alphabetically ascending order.

Input

The input consists of several words. The first line contains a number giving the number of words to follow. Each following line contains one word. A word consists of uppercase or lowercase letters from A to Z. Uppercase and lowercase letters are to be considered different. The length of each word is less than 13.

Output

For each word in the input, the output should contain all different words that can be generated with the letters of the given word. The words generated from the same input word should be output in alphabetically ascending order. An upper case letter goes before the corresponding lower case letter.

Sample Input

Sample Output

Hint

An upper case letter goes before the corresponding lower case letter.
So the right order of letters is ‘A'<‘a'<‘B'<‘b'<…<‘Z'<‘z’.
忘记了next_permutation的使用方法了,结果在生成全排列的时候忘记加自己写的cmp,还是使用了字典序WA了几次。。。
别的就没什么了=-= 看到很discuss里面很多人说用数组映射,完全不用好吗>_<

 

poj 2739 Sum of Consecutive Prime Numbers(筛法打表+前缀和)

Description

Some 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 prime
numbers, 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.

Input

The 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.

Output

The 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 Input

Sample Output

 

打个10000以内的素数表?然后前缀和处理连续的素数并进行计数?