[ACM ] 107 cat in the hat
請大家幫我review一下
看是哪一部份會超出時間
一直TLE 很沮喪
謝謝
//-----------------------------
#include<stdio.h>
#include<math.h>
int main(){
long initial_cat_height, total_cat_height;
long total_worker_cat, total_not_worker_cat;
long i,j,count;
printf( "%ld %ld\n" , (long)pow(9999,2),(long)pow(10000,2) ) ;
while(scanf("%ld %ld",&initial_cat_height,&total_worker_cat) == 2){
count = 0;
i = 2;
total_cat_height = 0;
if(initial_cat_height == 0 && total_worker_cat == 0)
return 0;
if(total_worker_cat == 1)
i = 1;
if( initial_cat_height == 1 ) {
printf( "0 %ld\n" , total_worker_cat ) ;
}
else {
for(j = 0;;j++){
if((long)pow(i,j) == total_worker_cat && (long)pow(i+1,j) ==
initial_cat_height){
break;
}
if(pow(i,j) > total_worker_cat){
i++;
j = 0;
}
}/* i for N and j for counts (numbers of iterations)*/
if(i == 1)
total_not_worker_cat = j;
else
total_not_worker_cat = (long)((1 - pow(i,j)) / (1 - i));
while(j >= 0){
// total_not_worker_cat += (long)( pow(i,j));
total_cat_height += (long)(pow(i,j)/pow(i+1,j)*initial_cat_height);
j--;
}
printf("%ld %ld\n",total_not_worker_cat,total_cat_height);
}
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 124.8.78.129
→
07/07 01:12, , 1F
07/07 01:12, 1F
→
07/07 01:12, , 2F
07/07 01:12, 2F
推
07/07 23:38, , 3F
07/07 23:38, 3F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章