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;
    }
  • 相关阅读:
    apache2三种模式及切换到event模式
    MySQL添加用户、创建数据库、分配权限
    ExcelHelper导出
    C#中将错误写进日志文件
    k3 cloud金蝶云参数设置云之家集成,提示无法推送企业消息
    k3 cloud中用视图类型来展示数据
    k3 cloud python 插件实现点击对应的单据编号打开单据
    k3 cloud单据转换的表
    sql server查询某个表对应的触发器
    QPainter::begin: Paint device returned engine == 0, type: 3
  • 原文地址:https://www.cnblogs.com/vongang/p/2114982.html
Copyright © 2011-2022 走看看