1. The main idea is to find the same number of characteristics between I and J cows, and the maximum value of output j-i;
2. We can find out sum[i][j], that is, the number of J characteristics that start at the beginning of the cow, assuming that the 1 characteristics between I and j occur the same number of times, the other features between IJ correspond to the difference of 1,
So we can use sum[i][j]-sum[i][1]; Constructs a key value to find with a hash.
3. Easy wrong point, add Hash is sum[0][j], also want to consider, otherwise can not calculate the first cow, second reading to use scanf;
4. Source code
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace Std;
const int prime=99991;
struct Node
{
int x;
Node *next;
};
Node hash[100000];
int sum[100010][40]={0};
int n,k;
int ans=0;
Ifstream in ("I:\\data.txt");
int check (int s,int t)
{
BOOL Flag=true;
if (s==-1) s=0;
int g=sum[t][1]-sum[s][1];
for (int j=2;j<=k;j++)
if (sum[t][j]-sum[s][j]!=g) Flag=false;
if (flag) return ABS (T-s);
return 0;
}
void Inserthash (int key,int j)
{
if (hash[key].x==0)
{
if (j==0) j=-1;
Hash[key].x=j;
return;
}
Node *p=&hash[key],*pp;
while (P!=null)
{
Pp=p;
p=p->next;
}
Node *p1= new node;
p1->x=j;
p1->next=null;
pp->next=p1;
p=&hash[key];
while (P!=null)
{
int Anss=check (P->X,J);
if (ANS<ANSS) {ans=anss;} cout<<p->x<< "" <<j<<endl;}
p=p->next;
}
}
void Makehash ()
{
ans=0;
int i,j;
for (i=0;i<100000;i++) {hash[i].x=0;hash[i].next=null;}
for (i=0;i<=n;i++)
{
int key=0;
for (j=2;j<=k;j++)
KEY=KEY+SUM[I][J]-SUM[I][1];
cout<<key<<endl;
Inserthash (ABS (key)%prime,i);
}
}
int main ()
{
int a[40];
int i,j,s;
cin>>n>>k;
for (i=1;i<=n;i++)
{
scanf ("%d", &s);
for (j=1;j<=k;j++)
{
sum[i][j]=sum[i-1][j]+s%2;
cout<<sum[i][j]<< "";
S=S/2;
}
cout<<endl;
}
Makehash ();
cout<<ans<<endl;
return 0;
}
poj3274 Problem Solving Report