這題被視為輕鬆過關的題目,
最後我看了一下大家的解法也是簡單到不行
這是我第一次寫的,完全就是腦中想什麼就寫了,
只讓input和output對上,殊不知已經超時,
我想也是,因為數字太大就不行了
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include<math.h> | |
#include <iomanip> | |
using namespace std; | |
/*第一次寫的,在uva拿到Time limit exceeded*/ | |
int main() | |
{ | |
int n,m; | |
int i=0,j=0,sum=0; | |
cin>>n; | |
cin>>m; | |
while(n>0){ | |
while(i<m){ | |
int ans = i; | |
sum=i; | |
for(j=n-1;j>0;j--){ | |
sum = sum*i; | |
} | |
if(sum==m){ | |
cout<<ans<<endl; | |
break; | |
} | |
i=ans; | |
i++; | |
} | |
cin>>n; | |
cin>>m; | |
} | |
return 0; | |
} |
第二次學乖了,看了別人的c寫法自己也做了一個C++版
但是卻是wrong answer
我真的不曉得錯在哪兒,如果有高手請指點啊
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include<math.h> | |
#include <iomanip> | |
using namespace std; | |
/*拿到Wrong answer*/ | |
int main() | |
{ | |
double n,p; | |
while(cin>>n>>p){ | |
cout<<pow(p,1/n)<<endl; | |
} | |
return 0; | |
} |
改這樣就沒問題了
回覆刪除#include
#include
#include
using namespace std;
int main(int argc, char** argv) {
double a,b;
while(cin>>a>>b){
cout<<fixed<<setprecision(0)<<pow(b,1.0/a)<<'\n';
}
return 0;
}
謝謝解題!您未來大有可為阿,我太久沒解題有點忘了當初卡的點了哈哈,複習一下~
刪除