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;
    }
  • 相关阅读:
    无穷有界数列,必有收敛子列(待证)
    有界闭区间内的连续函数必然有界
    数学分析提纲目录
    有限覆盖定理
    函数极限的柯西收敛准则
    数列的柯西收敛准则证明-----华东师大构造数列证明法
    数列柯西收敛准则的子列收敛证明法(取自中科大数分教材)
    用有限覆盖证明闭区间上的连续函数,必然一致连续
    数据库-模糊查询-like关键字-练习
    数据库-基础查询-练习
  • 原文地址:https://www.cnblogs.com/vongang/p/2114982.html
Copyright © 2011-2022 走看看