当前位置: 代码迷 >> C语言 >> [讨论]]第十五期编程题目
  详细解决方案

[讨论]]第十五期编程题目

热度:340   发布时间:2007-05-18 17:06:11.0
[讨论]]第十五期编程题目
Palindrome Numbers

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 1508 Accepted Submit: 561

A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, the name "anna" is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionally numbers can of course be ordered in size. The first few palindrome
numbers are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, ...

The number 10 is not a palindrome (even though you could write it as 010) but a zero as leading digit is not allowed.


Input

The input consists of a series of lines with each line containing one integer value i (1<= i <= 2*10^9 ). This integer value i indicates the index of the palindrome number that is to be written to the output, where index 1 stands for the first palindrome number (1), index 2 stands for the second palindrome number (2) and so on. The input is terminated by a line containing 0.


Output

For each line of input (except the last one) exactly one line of output containing a single (decimal) integer value is to be produced. For each input value i the i-th palindrome number is to be written to the output.


Sample Input

1
12
24
0


Sample Output

1
33
151

/*简单翻译一下,把回文数字从小到大排列.输入n输出对应第n个回文数字 */


Visible Lattice Points

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 740 Accepted Submit: 352

A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For example, the point (4, 2) is not visible since the line from the origin passes through (2, 1). The figure below shows the points (x, y) with 0 <= x, y <= 5 with lines from the origin to the visible points.

Write a program which, given a value for the size, N, computes the number of visible points (x,y) with 0 <= x, y <= N.

Input

The first line of input contains a single integer C, (1 <= C <= 1000) which is the number of datasets that follow.

Each dataset consists of a single line of input containing a single integer N, (1 <= N <= 1000), which is the size.

Output

For each dataset, there is to be one line of output consisting of: the dataset number starting at 1, a single space, the size, a single space and the number of visible points for that size.

Sample Input

4
2
4
5
231

Sample Output

1 2 5
2 4 13
3 5 21
4 231 32549

/*输入一个数字n代表一个方格的宽度.方格的左下角是原点,方格中点的坐标都是整数.如果方格中有某个点与原点的连线不经过另外的点则称做这一点是可以从原点看见的.
输入 n
输出 可以看见点的个数.


最近发现论坛上有很多人在ZJU上做题目所以发了这两个题目.
大家可以把自己代码到下面地址去提交测试.
http://acm.zju.edu.cn/show_problem.php?pid=2000
http://acm.zju.edu.cn/show_problem.php?pid=2777
鼓励写的好的发上来让大家学习.没有通过的也可以发上来让大家一起来找出错误.

另外如果有愿意发每期题目的人请和我说一下

搜索更多相关的解决方案: 编程  example  numbers  course  

----------------解决方案--------------------------------------------------------

没有人做难道是太简单了.
做出一个我给100,
两个都对的给300.
大家加油啊!
----------------解决方案--------------------------------------------------------
虽然我不能做了,但是帮顶一下
----------------解决方案--------------------------------------------------------

下面是我编的解决第一个问题的程序,如有不合理的地方请高手指出。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define INPUT_LEN 50 //最多能输入数字的个数
#define MAXLEN 10 //字符串最大长度
#define GREATEST 2000000000 //最大能输入的数字
typedef int Status;


Status Check(int num)//判断num是否为 Palindrome Numbers
{
int i = 0,p1 = 0, p2;
int isPal = 1;
char *s = (char *) malloc(MAXLEN * sizeof( char));
itoa(num , s, MAXLEN);
strcat(s, "$");
while(s[i] != '$') i++;
p2 = i-1;

while(p1 < p2)
{
if(s[p1] != s[p2])
isPal = 0;
p1++;
p2--;
}
return isPal;
}

void main()
{
int i, j = 0,n = 0, input_len, inp;
int *input = (int *)malloc(INPUT_LEN * sizeof(int));//输入
int *output = (int *)malloc(INPUT_LEN * sizeof(int));//输出
double time1;//用于计算时间
double time2;

printf("Input numbers (terminate it with 0): \n");

i = -1;
do
{
i++;
scanf("%d",&input[i]);
}
while(input[i] != 0 && i < INPUT_LEN);

input_len = i;//输入整数的个数
inp = input_len;// inp 用于循环判断
i = 1;



time1 = (double) clock()/CLOCKS_PER_SEC;

do
{
if(Check(i))
{
n++;
for( j = 0; j < input_len; j++)
{
if(n == input[j])
{
inp--;
output[j] = i;
break;
}
}
}
i++;
}
while(inp > 0 && i <= GREATEST);

printf("Output: \n");
for( j = 0; j < input_len; j++)
printf(" %d \n",output[j]);

time2 = (double)clock()/CLOCKS_PER_SEC;
printf(" used: %f second \n", (time1 - time2));
}


----------------解决方案--------------------------------------------------------

太强了 我的技术 只能帮顶了~~ 大家加油。


----------------解决方案--------------------------------------------------------
回复:(herbert_1987)下面是我编的解决第一个问题的...

这样算答案肯定是没有错.
但是首先时间是没有办法在1000MS.
其次就是如果输入的是2000000000的话这个结果可能没有办法用一个数据类型来表示


----------------解决方案--------------------------------------------------------
题目要求(1&lt;= i &lt;= 2*10^9 ),那该怎办?
----------------解决方案--------------------------------------------------------
仔细想想就明白了.
不要想把那个数字用一个数字来表示
----------------解决方案--------------------------------------------------------
哦,难道用字符?
----------------解决方案--------------------------------------------------------
虽然现在还看不懂,但是还是顶下先。。。不容易呀
----------------解决方案--------------------------------------------------------
  相关解决方案