2007-08-13 00:34
2007-08-13 06:32
嗯,这算法应该对的,就是慢了点。
可是无论如何第9个数据总是过不了,如果数组用int只能过6个数据,数组用double只能过9个数据(第9个过不了),甚至为了数据正确我使用高精度计算,竟然也只能过6个数据

2007-08-13 08:44
/*---------------------------------------------------------------------------
File name: NKU1021-[NKPC2]?S???.c
Author: HJin (email: fish_sea_bird [at] yahoo [dot] com )
Created on: 8/12/2007 21:29:53
Environment: Windows XP Professional SP2 English +
Visual Studio 2005 v8.0.50727.762
Modification history:
===========================================================================
I think I discussed this problem with Leeco before. Bottom of line is:
write out the binary representation of n.
Following is my code submitted to Nankai online judge.
*/
long long b[] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721, 129140163, 387420489, 1162261467, 3486784401, 10460353203, 31381059609, 94143178827, 282429536481, 847288609443, 2541865828329, 7625597484987, 22876792454961, 68630377364883, 205891132094649, 617673396283947};
int main()
{
int k;
unsigned n;
while( scanf("%u", &n) != -1 )
{
--n;
k=0;
while(n)
{
if(n&1)
printf("%lld\n", b[k]);
++k;
n >>= 1;
}
}
return 0;
}

2007-08-13 12:39
这个Judge现在有问题,全部的CODE都判成编译错,我觉得这个代码应该没问题
#include <stdio.h>int main()
{
int k,n;
while(scanf(\"%d %d\",&k,&n)!=EOF){
int res=0,t=1;
while(n){
if(n%2){
res+=t;
}
t*=k;
n/=2;
}
printf(\"%d\n\",res);
}
}
你的算法很好啊
不过有个问题想请教
这个程序似乎算不到 N 1000 为什么能过呢? 

2007-08-13 15:20
/*---------------------------------------------------------------------------
File name: NKU1021-[NKPC2]?S???.c
Author: HJin (email: fish_sea_bird [at] yahoo [dot] com )
Created on: 8/12/2007 21:29:53
Environment: Windows XP Professional SP2 English +
Visual Studio 2005 v8.0.50727.762
Modification history:
===========================================================================
I think I discussed this problem with Leeco before. Bottom of line is:
write out the binary representation of n.
Following is my code submitted to Nankai online judge.
*/
long long b[] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721, 129140163, 387420489, 1162261467, 3486784401, 10460353203, 31381059609, 94143178827, 282429536481, 847288609443, 2541865828329, 7625597484987, 22876792454961, 68630377364883, 205891132094649, 617673396283947};
int main()
{
int k;
unsigned n;
while( scanf("%u", &n) != -1 )
{
--n;
k=0;
while(n)
{
if(n&1)
printf("%lld\n", b[k]);
++k;
n >>= 1;
}
}
return 0;
}
与这道题不完全一样,输入样例后过不了,这道题的规模在int内,不需要long long

2007-08-13 16:32

2007-08-13 17:44
又看到这个结果了,我用int,unsigned和高精度都是这个结果,也不知道为什么,你换成double可以看到结果是90分

2007-08-13 17:47
2007-08-13 17:48
这个算法应该没有错啊
我也是这么想的,因为10个数据可以过9个...运算中的精度问题也可以排除,因为我用高精度也只过6个,我提交了10多次,依旧不AC,所以才发出来请教大家的

2007-08-13 17:53