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 zhu_shui1989 at 2009-08-17 16:38:16 on Problem 2739
#include <iostream>
using namespace std;
inline void ss(int n);
inline void jia(int m);
int b[2000],e,q;
int main()
{
   b[0]=2;b[1]=3;
   int a[10005],i;
  for( i=0;i<10005;i++)
  {cin>>a[i];
     if(a[i]==0)
		 break;}
  for(int j=0;j<i;j++)
  {
	  if(a[j]==2||a[j]==3)
		  cout<<1<<endl;
	  else
	  {
		 jia(a[j]);
	  }}}
inline void ss(int n)
{
	e=2;
	for(int j=4;j<=n;j++)
	{
		for(int k=2;k<=j/2;k++)
		{
		if(j%k==0)
		break;
		if(k==(j/2))
		{
		b[e]=j;
		e++;
		}}}}
inline void jia(int m)
{
    ss(m);
	int max;
	q=0;
    for(int x=0;x<e-1;x++)
	  {
		  max=b[x];
	  for(int y=x+1;y<e-1;y++)
	  { max+=b[y];
      if(max==m)
		  q++;
	  else
		 continue;}}
	  if(b[e-1]==m)
		  cout<<q+1<<endl;
	  else
		  cout<<q<<endl;
}

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