/*---------------------------------------------------------------------------
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;
}
这个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 为什么能过呢?
/*---------------------------------------------------------------------------
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
又看到这个结果了,我用int,unsigned和高精度都是这个结果,也不知道为什么,你换成double可以看到结果是90分