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 |
哎,超时真麻烦,那位大牛给点思路下面是我的代码,谢谢啊#include<iostream> using namespace std; int p(int a,int b,int c,int d,int e,int f,int g,int h,int i) { int m,n; if(i==0) return a; if(i==1) return b; if(i==2) return c; if(i>=3) { if(i%2!=0) { m=d*p(a,b,c,d,e,f,g,h,i-1)+e*p(a,b,c,d,e,f,g,h,i-2)-f*p(a,b,c,d,e,f,g,h,i-3); if(m>=0) return m%g; else return g+m%g; } else { n=f*p(a,b,c,d,e,f,g,h,i-1)-d*p(a,b,c,d,e,f,g,h,i-2)+e*p(a,b,c,d,e,f,g,h,i-3); if(n>=0) return n%h; else return n%h+h; } } } int main() { int n; cin>>n; int k; int a,b,c,d,e,f,g,h,i; for(k=0;k<n;k++) { cin>>a>>b>>c>>d>>e>>f>>g>>h>>i; cout<<p(a,b,c,d,e,f,g,h,i)<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator