poj3274 Problem Solving Report

Source: Internet
Author: User

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-&GT;X,J);
if (ANS&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.