NOIP2013考前练手
输入n,n个数,a
判断a有没在这组数内
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include <iostream> #include <cstring> using namespace std; long long hs[1000007]={0}; bool pd[1000007]; inline int hash(long long x) { int a=x%1000007; while(pd[a]==1&&hs[a]!=x)a=(a+1)%1000007; pd[a]=1; return a; } int main() { memset(pd,false,sizeof(pd)); int n; long long a; cin>>n; for(int i=1;i<=n;i++) {cin>>a;hs[hash(a)]=a;} cin>>a; if(hs[hash(a)]==a)cout<<"yes"; else cout<<"no"; return 0; } |
Subscribe