标签:
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 726 Accepted Submission(s):
326
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<ctype.h> using namespace std; const int maxn=1000100; const int HM=1000100; int n,m; struct Hash { int date; int cnt; Hash *next; }; Hash H[maxn]; inline int read() { char c=getchar(); while(!isdigit(c)) c=getchar(); int f=c-‘0‘; while(isdigit(c=getchar())) f=f*10+c-‘0‘; return f; } int h(int x) { return x%HM; } void insert(Hash*H,int date) { int key=h(date); Hash *pre=&H[key],*p=pre->next; while(p!=NULL){ if(p->date==date){ p->cnt++; return; } pre=p; p=p->next; } p=(Hash*)malloc(sizeof(Hash)); pre->next=p; p->next=NULL; p->date=date; p->cnt=1; } void find_del_output(Hash*H,int date) { int key=h(date); Hash *pre=&H[key],*p=pre->next; while(p!=NULL){ if(p->date==date){ printf("%d\n",p->cnt); pre->next=p->next;///删掉结点 free(p); return; } pre=p; p=p->next; } puts("0"); } int main() { while(cin>>n>>m){ memset(H,0,sizeof(H)); while(n--){ int h=read(); insert(H,h); } while(m--){ int q=read(); find_del_output(H,q); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/--560/p/4394394.html