• [code]poj3349 Snowflake Snow Snowflakes


    哈希+挂链。可以用next数组挂链。
     1 const p=99987;
     2 type
     3   arr=array[1..6]of longint;
     4 var
     5   a,b:Array[0..200000]of arr;
     6   next:Array[0..200000]of longint;
     7   i,j,n,has,tot:longint;
     8 
     9 function hash(x:longint):longint;
    10   var i:longint;
    11   begin
    12   hash:=0;
    13   for i:=1 to 6 do
    14     hash:=(hash*7+a[x,i]*131) mod p;
    15   inc(hash);
    16   end;
    17 function equa(a,b:arr):boolean;
    18   var i:longint;
    19   begin
    20   for i:=1 to 6 do
    21     if a[i]<>b[i] then exit(false);
    22   exit(true);
    23   end ;
    24 procedure sort(var a:arr);
    25   var i,j,t:longint;
    26   begin
    27   for i:=1 to 5 do
    28     for j:=i to 6 do
    29       if a[j]>a[i] then
    30         begin t:=a[j];a[j]:=a[i];a[i]:=t;end;
    31   end;
    32 
    33 begin
    34   readln(n);
    35   tot:=p+1;
    36   for i:=1 to n do
    37     begin
    38     for j:=1 to 6 do
    39       read(a[i,j]);
    40     sort(a[i]);
    41     has:=hash(i);
    42     while (has<>0)and(not equa(b[has],b[200000])) do
    43       begin
    44       if equa(b[has],a[i]) then
    45         begin
    46         writeln('Twin snowflakes found.');
    47         halt;
    48         end;
    49       has:=next[has];
    50       end;
    51     next[has]:=tot+1; inc(tot);
    52     b[has]:=a[i];
    53     end;
    54   writeln('No two snowflakes are alike.');
    55   end.
    View Code



    ------------------------------------------------------------------------- 花有重开日,人无再少年
  • 相关阅读:
    adb shell am pm 用法
    HTML的属性和css基础
    HTML的实际演练2
    HTML的实际演练1
    HTML的标签简介
    HTML的基础知识
    Python之 ---成员修饰符
    Python基础之-----------函数
    Python之-------基础数据类型
    Python之内置函数
  • 原文地址:https://www.cnblogs.com/lbz007oi/p/3364201.html
Copyright © 2020-2023  润新知