zoukankan      html  css  js  c++  java
  • POJ_3349 Snowflake Snow Snowflakes

    Snowflake Snow Snowflakes
    Time Limit: 4000MS Memory Limit: 65536K
    Total Submissions: 18478 Accepted: 4770

    Description

    You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowflakes, and search for a pair that may be identical. Each snowflake has six arms. For each snowflake, your program will be provided with a measurement of the length of each of the six arms. Any pair of snowflakes which have the same lengths of corresponding arms should be flagged by your program as possibly identical.

    Input

    The first line of input will contain a single integer n, 0 < n ≤ 100000, the number of snowflakes to follow. This will be followed by n lines, each describing a snowflake. Each snowflake will be described by a line containing six integers (each integer is at least 0 and less than 10000000), the lengths of the arms of the snow ake. The lengths of the arms will be given in order around the snowflake (either clockwise or counterclockwise), but they may begin with any of the six arms. For example, the same snowflake could be described as 1 2 3 4 5 6 or 4 3 2 1 6 5.

    Output

    If all of the snowflakes are distinct, your program should print the message:
    No two snowflakes are alike.
    If there is a pair of possibly identical snow akes, your program should print the message:
    Twin snowflakes found.

    Sample Input

    2
    1 2 3 4 5 6
    4 3 2 1 6 5

    Sample Output

    Twin snowflakes found.

    Source

    View Code
    #include <stdio.h>
    #include
    <string.h>
    #define len 140000
    #define mod 139997
    #define N 100010

    int flack[N][6];

    struct node
    {
    int key;
    struct node * next;
    }snow[N];

    struct node *hash[len];

    int get_int(void)
    {
    char ch;
    int num = 0;
    while((ch = getchar())== ' ' || ch == '\n')
    ;
    while(ch >= '0' && ch <= '9')
    {
    num
    = num * 10 + ch - '0';
    ch
    = getchar();
    }
    return num;
    }

    int same(int x, int y)
    {
    int i, j, k;
    int tmp[12];
    for(i = 0; i < 6; i++)
    {
    tmp[i]
    = flack[x][i];
    tmp[i
    +6] = flack[x][i];
    }
    j
    = 0;
    i
    = 0;
    while(i < 12)
    {
    while(i < 12 && tmp[i] != flack[y][j])
    i
    ++;
    k
    = i;
    while(i < 12 && tmp[i] == flack[y][j])
    {
    j
    ++;
    i
    ++;
    if(j == 6)
    return 1;
    }
    i
    = k+1;
    j
    = 0;
    }
    i
    = 11;
    while(i >= 0)
    {
    while(i >= 0 && tmp[i] != flack[y][j])
    i
    --;
    k
    = i;
    while(i >= 0 && tmp[i] == flack[y][j])
    {
    i
    --;
    j
    ++;
    if(j == 6)
    return 1;
    }
    j
    = 0;
    i
    = k-1;
    }
    return 0;
    }

    int check(struct node *l, int i)
    {
    while(l != NULL)
    {
    if(same(l->key,i))
    return 1;
    l
    = l->next;
    }
    return 0;
    }

    int main()
    {
    int n, i, j, flag = 0, sum;
    scanf(
    "%d",&n);
    for(i = 1; i <= n; i++)
    {
    sum
    = 0;
    for(j = 0; j < 6; j++)
    {
    flack[i][j]
    = get_int();
    sum
    += flack[i][j];
    }
    sum
    %= mod;
    snow[i].key
    = i;
    if(hash[sum] == NULL)
    {
    hash[sum]
    = &snow[i];
    }
    else if(check(hash[sum],i))
    {
    flag
    = 1;
    break;
    }
    else
    {
    snow[i].next
    = hash[sum];
    hash[sum]
    = &snow[i];
    }
    }
    if(flag)
    printf(
    "Twin snowflakes found.\n");
    else
    printf(
    "No two snowflakes are alike.\n");
    return 0;
    }
  • 相关阅读:
    代理模式的理解和示例
    模板方法模式的理解和使用
    ubuntu16.04安装matlab_R2018a/R2017a
    c++ 智能指针用法详解
    ORBSLAM2单目初始化过程
    ROS launch 总结
    组合导航初理解
    对极几何-本质矩阵-基本矩阵
    学习OpenCV双目测距原理及常见问题解答
    Ubuntu 16.04 一系列软件安装命令,包括QQ、搜狗、Chrome、vlc、网易云音乐安装方法(转载)
  • 原文地址:https://www.cnblogs.com/vongang/p/2114982.html
Copyright © 2011-2022 走看看