Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我的哪里有问题呢.......(给出的数据通过)但是还是 wa#include<iostream> using namespace std; int f(int& ml,int &m,int b,int n); int pow(int a,int n); int main() { int b,n,a,ml,m,k; cin>>b>>n; while(b&&n) { ml=1;m=b; k=f(ml,m,b,n); if(k) cout<<k<<endl; else if(pow(ml,n)+pow(m,n)>=2*b) cout<<ml<<endl; else cout<<m<<endl; cin>>b>>n; } } int f(int& ml,int &m,int b,int n) { //cout<<ml<<" "<<m<<" "; int res=0,t=1; for(int i=n;i&&t<=b;i--) t*=(ml+m)/2;//cout<<" "<<t<<endl; if(ml==m||ml+1==m) return 0; if(t==b) return (ml+m)/2; else if(t>b) { m=(ml+m)/2; res=f(ml,m,b,n); } else if(t<b) { ml=(ml+m)/2; res=f(ml,m,b,n); } return res; } int pow(int a,int n) { int t=1; for(int i=n;i;i--) t*=a; return t; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator