Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哎,超时真麻烦,那位大牛给点思路下面是我的代码,谢谢啊

Posted by ZhangJunhua at 2008-07-26 09:42:18 on Problem 2696
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator