zoukankan      html  css  js  c++  java
  • HDU 4334 Trouble [二分哈希]

      很老的题了,一开始懒的写HASH写个二分查找还没过,后来改成HASH就A了。。

      

     1 #include <stdio.h>
     2 #include <string.h>
     3 #define MOD 999997
     4 #define PRI 199
     5 typedef __int64 LL;
     6 LL add=10000000000000000LL;
     7 int cas,n;
     8 LL d[5][201];
     9 LL num[MOD];
    10 int first[MOD],next[MOD/2],es;
    11 void ins(LL x,int p){
    12     num[es]=x,next[es]=first[p],first[p]=es++;
    13 }
    14 bool findhash(LL x){
    15     int p=(x+add)%MOD;
    16     for(int i=first[p];i!=-1;i=next[i])if(num[i]==x)return 1;
    17     return 0;
    18 }
    19 void inshash(LL x){
    20     if(!findhash(x)){
    21         int p=(x+add)%MOD;
    22         ins(x,p);
    23     }
    24 }
    25 int main(){
    26 //freopen("test.in","r",stdin);
    27     scanf("%d",&cas);
    28     for(int ca=1;ca<=cas;ca++){
    29         scanf("%d",&n);
    30         memset(first,-1,sizeof first);es=0;
    31         for(int i=0;i<5;i++)
    32             for(int j=0;j<n;j++)
    33                 scanf("%I64d",&d[i][j]);
    34         for(int i=0;i<n;i++)
    35             for(int j=0;j<n;j++)
    36                 inshash(d[0][i]+d[1][j]);
    37         int find=0;
    38         for(int i=0;i<n&!find;i++)
    39             for(int j=0;j<n&&!find;j++)
    40                 for(int k=0;k<n&&!find;k++)
    41                     find=findhash(-d[2][i]-d[3][j]-d[4][k]);
    42         printf(find?"Yes\n":"No\n");
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    __del__ 析构方法 __init__ 构造方法
    单态模式
    面向对象小练习2
    __new__ '''魔术方法
    菱形继承
    继承:多继承
    继承: .单继承
    面向对象小练习
    __init__ 魔术方法
    如何访问私有成员
  • 原文地址:https://www.cnblogs.com/swm8023/p/2661265.html
Copyright © 2011-2022 走看看