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 ACM_henry at 2008-10-16 14:23:17 on Problem 1200
#include <iostream>
using namespace std;
char p[16000010];
const int prim=111111111;
int hash[prim];
int find(int v) {
    int a = v / 32;
    int b = v % 32;
    return (hash[a]&(1<<b));
}

void insert(int v) {
    int a = v / 32;
    int b = v % 32;
    hash[a] |= 1 << b;
}

int main()
{
	int length,num;
	cin>>length>>num;
	scanf("%s",p);
	int sum;
	int i;
	int j;
	int ans=0;
	for(i=0;i<=strlen(p)-length;i++)
	{
		sum=0;
		for(j=i;j<i+length;j++)
		{
			sum+=num*sum+p[j]-'a';
		}
		if(find(sum)==0)
		{
			ans++;
		}
		insert(sum);
	}
	cout<<ans<<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