• UVa 3349 Snowflake Snow Snowflakes(Hash)


     http://poj.org/problem?id=3349

    题意:

    给出n片雪花留个角的长度,要求判断是否有一样的雪花。

    思路:

    Hash表的应用。

    首先将每个雪花所有角的总长计算出来,如果两片雪花相同的话那么总长也是相同的,然后加入vector容器当中,最后遍历vector数组,如果某个总长有大于1的雪花数,则有可能存在相同的雪花,此时需要比较这些雪花。

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <vector>
     4 #include <cmath>
     5 #include <algorithm>
     6 using namespace std;
     7 const int maxn = 100002;
     8 const int prime = 99991;
     9 
    10 struct node
    11 {
    12     int len[6];
    13 }snow;
    14 
    15 vector<node>hs[prime];
    16 
    17 
    18 bool judge(node a, node b)
    19 {
    20     for (int i = 0; i<6; i++)
    21     {
    22         if (a.len[0] == b.len[i] && a.len[1] == b.len[(i + 1) % 6] && a.len[2] == b.len[(i + 2) % 6] &&
    23             a.len[3] == b.len[(i + 3) % 6] && a.len[4] == b.len[(i + 4) % 6] && a.len[5] == b.len[(i + 5) % 6])
    24             return true;//固定a,顺时针比较
    25         if (a.len[0] == b.len[i] && a.len[1] == b.len[(i + 5) % 6] && a.len[2] == b.len[(i + 4) % 6] &&
    26             a.len[3] == b.len[(i + 3) % 6] && a.len[4] == b.len[(i + 2) % 6] && a.len[5] == b.len[(i + 1) % 6])
    27             return true;//固定a, 逆时针比较
    28     }
    29     return false;
    30 }
    31 
    32 int main()
    33 {
    34     //freopen("D:\txt.txt", "r", stdin);
    35     int n;
    36     cin >> n;
    37     while (n--)
    38     {
    39         for (int i = 0; i<6; i++)
    40             scanf("%d", &snow.len[i]);
    41         int sum = (snow.len[0] + snow.len[1] + snow.len[2] + snow.len[3] + snow.len[4] + snow.len[5]) % prime;
    42         hs[sum].push_back(snow);
    43     }
    44     for (int i = 0; i<prime; i++)
    45     if (hs[i].size()>1)     //可能有相同的雪花
    46     {
    47         for (int j = 0; j<hs[i].size(); j++)
    48         for (int k = j + 1; k<hs[i].size(); k++)
    49         {
    50             if (judge(hs[i][j], hs[i][k]))
    51             {
    52                 printf("Twin snowflakes found.");
    53                 return 0;
    54             }
    55         }
    56     }
    57     printf("No two snowflakes are alike.");
    58     return 0;
    59 }

          

  • 相关阅读:
    C#枚举中使用Flags特性
    WPF 设置输入只能英文
    PHP array_merge_recursive() 函数
    PHP array_merge() 函数
    PHP array_map() 函数
    PHP array_keys() 函数
    PHP array_key_exists() 函数
    [HNOI2016]网络
    WPF 设置输入只能英文
    WPF 设置输入只能英文
  • 原文地址:https://www.cnblogs.com/zyb993963526/p/6367823.html
Copyright © 2020-2023  润新知