| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1691 人关注过本帖
标题:[讨论]]第十三期编程题目
取消只看楼主 加入收藏
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
 问题点数:0 回复次数:9 
[讨论]]第十三期编程题目

由于pcrazyc斑竹临时有事情.这期还是由我来出题目.希望大家继续支持.
第一题:

k尾相等数
Time Limit:1000MS Memory Limit:10000K
Description:
从键盘上输入一个整数k(k>1),若存在整数m,n(m>n),使得pow(k,m)和pow(k,n)均大于或等于1000,且末尾3位数相等,则称m和n是一对"k尾相等数"。请编写一程序求m+n值最小的k尾相等数。
input:
每行输入一个整数k;
output:
输出相应的最小m+n值;
sample input:
2
sample output
120


第二题:


Lagrange's Four-Square Theorem
Time Limit:1000MS Memory Limit:30000K
Total Submit:790 Accepted:339

Description
The fact that any positive integer has a representation as the sum of at most four positive squares (i.e. squares of positive integers) is known as Lagrange's Four-Square Theorem. The first published proof of the theorem was given by Joseph-Louis Lagrange in 1770. Your mission however is not to explain the original proof nor to discover a new proof but to show that the theorem holds for some specific numbers by counting how many such possible representations there are.
For a given positive integer n, you should report the number of all representations of n as the sum of at most four positive squares. The order of addition does not matter, e.g. you should consider 4^2 + 3^2 and 3^2 + 4^2 are the same representation.

For example, let's check the case of 25. This integer has just three representations 1^2+2^2+2^2+4^2, 3^2 + 4^2, and 5^2. Thus you should report 3 in this case. Be careful not to count 4^2 + 3^2 and 3^2 + 4^2 separately.


Input
The input is composed of at most 255 lines, each containing a single positive integer less than 2^15, followed by a line containing a single zero. The last line is not a part of the input data.

Output
The output should be composed of lines, each containing a single integer. No other characters should appear in the output.

The output integer corresponding to the input integer n is the number of all representations of n as the sum of at most four positive squares.

Sample Input

1
25
2003
211
20007
0

Sample Output

1
3
48
7
738

最后祝大家过一个愉快而又充实的五一!!!


简单翻译一下第二个:
就是把任意数字分解成不超过四个数字的平方和。{注意看紫色部分的例子说明}
问有多少种分法

[此贴子已经被作者于2007-4-27 17:08:31编辑过]

搜索更多相关主题的帖子: 题目 讨论 
2007-04-27 15:14
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
/*第二题的解答,不知道对不对?*/
我给你提交了一下.超出时间了.
再改进一点点就能过.

[此贴子已经被作者于2007-4-27 18:10:47编辑过]


2007-04-27 18:05
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
以下是引用Javal在2007-4-27 18:04:29的发言:

写了下第一题,好像有些问题,请指正,thanks!

#include<stdio.h>
#include<math.h>
#define TRUE 1
#define FALSE 0

struct mantissa
{
int mant;
int exponent;
};

int main( void )
{
int k = 0;
int m = 1;
int n = 0;
int index = 0;
int i = 0;
int j = 0;
int flag = FALSE;
struct mantissa arr[1000];
for (i = 0; i < 1000; ++i)
{
arr[i].mant = 0;
}

printf("Please enter the value of k:\n");
scanf("%d", &k);

for (index = 0; pow(k, index) < 1000; ++index)
continue;

i = 0;
while(1)
{
if (i == 0)
{
arr[i].mant = (int)pow(k, index) % 1000;
}
else
{
arr[i].mant = (arr[i-1].mant * k) % 1000;
}
arr[i].exponent = index;
// printf("%d\t%d\n", arr[i].mant, arr[i].exponent);

for (j = 0; j < i; ++j)//这里需要改进.
{
if (arr[i].mant == arr[j].mant)
{
flag = TRUE;
m = arr[i].exponent;
n = arr[j].exponent;
break;
}
}
if (flag)
{
break;
}
i++;
index++;
}

printf("%d\n", m + n);

return 0;
}

我看了一下思路基本上是对了.因为你求余数的方法很正确.估计错误不是很大.找找那写边界的地方
你还有这组数据不对:123454321  答案应该是27;


2007-04-27 18:23
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
这起题目比较简单.
大家加油.尤其是第二个只要多写点条件都能过.第二个大家自己
http://acm.pku.edu.cn/JudgeOnline/problem?id=2042提交.一定要注意输入输出不要输出没有用的东西.
第一个题目我给几个测试数据.要是都对的话就可以了:
输入      输出
25 7
125 6
1000 3
100000 102
123454321 27

2007-04-27 18:32
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
以下是引用yu_hua在2007-4-27 18:42:47的发言:

each containing a single positive integer less than 2^15==32768

这个是第二个题目的范围.
第一个题目的范围是long以内


2007-04-27 20:26
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 

n不能是7;
使得pow(k,m)和pow(k,n)均大于或等于1000,


2007-04-27 20:35
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
楼上的哥哥你把题目全看反了
我给的数据是测试k尾相等数的不是测试四平方数的
难到我在哪里表达有问题?????

2007-04-28 07:50
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
以下是引用hujian100在2007-4-28 21:18:07的发言:

第一题我根据三楼的思想也写了自己的程序,但发现有些结果运行不对,也不知道问题出在什么地方了,还请高手帮忙看看啊 关注中……多谢了!

#include <stdio.h>
#include <math.h>

void main()
{
int m, n, flag=1;
long int k, km_mant, kn_mant;
printf("Please entry the value of k(k>1):\n");
scanf("%d", &k);
for(m=2;;m++)
{
if( pow(k,m)<1000 )
continue;
else
{
km_mant = (int)pow(k,m)%1000;
for(n = 1; n < m; n++)
{
if( pow(k,n) >= 1000 )
{
kn_mant = (int)pow(k,n)%1000;
if( km_mant == kn_mant )
{
printf("%d+%d=%d\n", m, n, m+n);
flag=0;
break;
}
}
}
}
if(flag==0)
break;
}
printf("%d\t%d\n", (int)pow(k,m),(int)pow(k,n));
printf("%d\t%d\n", km_mant, kn_mant);
}

你和三楼思想还是不一样的.
你的不能计算出很大的n,m因为你的pow()是会超出数据范围


2007-04-29 08:48
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
以下是引用yu_hua在2007-4-29 7:30:00的发言:
/*----------------------------
Lagrange's Four-Square Theorem
-----------------------------*/
#include <stdio.h>
#include <math.h>
long Lagrange(long nn)
{ long way=0;
long a,b,c,d,a2,b2,c2,d2;
for(a=0,a2=a*a;a2<nn;a++,a2=a*a)
for(b=a,b2=b*b;a2+b2<nn;b++,b2=b*b)
for(c=b,c2=c*c,d=(long)sqrt(nn-a2-b2-c2),d2=d*d;d2>=c2;
d--,d2=d*d,c=(long)sqrt(nn-a2-b2-d2),c2=c*c)
if(a2+b2+c2+d2==nn)way++;
else if(c==b)
{
c=(long)sqrt(nn-a2-b2-d2);
if(a2+b2+c*c+d2==nn)way++;
}
return way;
}
main()
{
long n;
while(scanf("%ld",&n))
{
if(n<=0)break;
printf("%ld\n",Lagrange(n));
}
}

这个因该能过了


2007-04-29 08:50
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 

你可以到我给那个连接去提交就知道了.
或者用
include<time.h>
int begin,end
begin=clock();
end=clock();
end-begin;
但是时间很不稳定.而且也和机器有很大关系


2007-04-29 10:22
快速回复:[讨论]]第十三期编程题目
数据加载中...
 
   



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

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