作者Tribbiani (没有早知道这回事)
看板C_and_CPP
标题[ACM ] 107 cat in the hat
时间Tue Jul 7 01:12:03 2009
请大家帮我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
1F:→ Tribbiani:PS 跑了一些很大的资料也是都OK的说 07/07 01:12
2F:→ Tribbiani:还是有什麽会陷入回圈的CASE我没注意到呢@@ 07/07 01:12
3F:推 cutecpu:测测看 => 2147483647 2147483646 07/07 23:38