标题:[讨论]]第十五期编程题目
只看楼主
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
 问题点数:0 回复次数:27 
[讨论]]第十五期编程题目
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 
2007-05-18 17:06
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
得分:0 

没有人做难道是太简单了.
做出一个我给100,
两个都对的给300.
大家加油啊!

2007-05-18 21:01
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
得分:0 
虽然我不能做了,但是帮顶一下

雁无留踪之意,水无取影之心
2007-05-18 21:46
herbert_1987
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:1314
专家分:0
注 册:2007-5-13
得分:0 

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

#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));
}


人生重要的不是所站的位置,而是所朝的方向
2007-05-18 21:49
wtyi
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2007-5-3
得分:0 

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


blog http://wtyi. 欢迎访问 交流~
2007-05-18 21:56
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
得分:0 
回复:(herbert_1987)下面是我编的解决第一个问题的...

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


2007-05-18 22:18
herbert_1987
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:1314
专家分:0
注 册:2007-5-13
得分:0 
题目要求(1&lt;= i &lt;= 2*10^9 ),那该怎办?

人生重要的不是所站的位置,而是所朝的方向
2007-05-18 22:22
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
得分:0 
仔细想想就明白了.
不要想把那个数字用一个数字来表示

2007-05-18 22:34
herbert_1987
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:1314
专家分:0
注 册:2007-5-13
得分:0 
哦,难道用字符?

人生重要的不是所站的位置,而是所朝的方向
2007-05-18 22:43
ibiancheng
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2007-4-3
得分:0 
虽然现在还看不懂,但是还是顶下先。。。不容易呀

执著的信念,坚定的自信,勤奋的努力才是通向成功的捷径! !!
2007-05-19 00:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-140486-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.527239 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved