[ACM ] 107
在收到多次的tle跟wa終於受不了了
所以來問問各位大大,不知道問題出在哪邊
================以下是目前的code===================
#include <stdio.h>
#include <math.h>
int main()
{
unsigned long h,c;
while( scanf("%lu%lu",&h,&c) )
{
if((!h) || (!c))break;
if(h==1 && c==1)
{
printf("0 1\n");
continue;
}
unsigned long N = 1;
int k;
if(c==1) k=(int)( (float)log(h) / (float)log(2) );
else
{
while( ++N )
{
if(fabs( ((float)log(c)/(float)log(N))-
((float)log(h)/(float)log(N+1)) ) < 0.0001)
{
k=(int)((float)log(c) / (float)log(N));
break;
}
}
}
unsigned long SumOfNothing=0,SumOfHeight=c;
int height=h,nothing=1;
for(int i=0 ; i<k ; height /= (N+1), nothing *= N, ++i)
{
SumOfNothing += nothing;
SumOfHeight += height*nothing;
}
printf("%lu %lu\n",SumOfNothing,SumOfHeight);
}
return 0;
}
========================以上code======================
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.126.232.187
※ 編輯: frank99977 來自: 59.126.232.187 (04/19 00:25)
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章