Monthly Archives: March 2012

SPOJ Number Steps 解题报告

1112. Number Steps

Time Limit: 2s Source limit: 50000B

Description

Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2,... as shown in the figure. For example, 1, 2, and 3 has been written at points (1,1), (2,0), and (3, 1) respectively and this pattern has continued.

You are to write a program that reads the coordinates of a point (x, y), and writes the number (if any) that has been written at that point. (x, y) coordinates in the input are in the range 0...10000.

Input

The first line of the input is N, the number of test cases for this problem. In each of the N following lines, there is x, and y representing the coordinates (x, y) of a point.

Output

For each point in the input, write the number written at that point or write No Number if there is none.

Sample Input

3
4 2
6 6
3 4

Sample Output

6
12
No Number

继续水题,而且是以前做过的,找规律即可。

Read more »

SPOJ Adding Reversed Numbers 解题报告

42. Adding Reversed Numbers

Time Limit: 5s Source limit: 50000B

Description

The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies. Obviously, this work is very hard because the basic sense of the play must be kept intact, although all the things change to their opposites. For example the numbers: if any number appears in the tragedy, it must be converted to its reversed form before being accepted into the comedy play.

Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. For example, if the main hero had 1245 strawberries in the tragedy, he has 5421 of them now. Note that all the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200 gives 21). Also note that the reversed number never has any trailing zeros.

ACM needs to calculate with reversed numbers. Your task is to add two reversed numbers and output their reversed sum. Of course, the result is not unique because any particular number is a reversed form of several numbers (e.g. 21 could be 12, 120 or 1200 before reversing). Thus we must assume that no zeros were lost by reversing (e.g. assume that the original number was 12).

Input

The input consists of N cases (equal to about 10000). The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the reversed numbers you are to add.

Output

For each case, print exactly one line containing only one integer - the reversed sum of two reversed numbers. Omit any leading zeros in the output.

Sample Input

5 5
3
24 1
4358 754
305 794

Sample Output

34
1998
1

水题,把数字翻转过来,相加以后再翻转过去就可以了。一个函数解决。
......

Read more »

SPOJ Prime Generator 解题报告

2. Prime Generator

Time Limit: 6s Source limit: 50000B

Description

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

Input

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

Output

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

Sample Input

5 5
2
1 10
3 5

Sample Output

2
3
5
7
 
3
5

最近在看一些有限元方面的书,前人所写的程序几乎清一色的都是用Fortran,所以不得不复习一下Fortran了。据说同样的算法用Fortran实现的会比C/C++实现的快25%(当然我没测试过)。不过要找一个支持Fortran的OJ还真是不容易,因为Poj的Fortran编译器不知道出了什么问题,怎么都编译不了,所以只好选择SPOJ了,不过SPOJ支持的语言还真是多,简直可以说是无所不包。

Read more »