• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            poj3349

            Snowflake Snow Snowflakes

            Time Limit: 4000MS Memory Limit: 65536K
            Total Submissions: 22730 Accepted: 5923

            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.
             
            忽然發現自己已經好長時間沒寫過hash的題目了
            這題寫了半天,覺著寫的特別混亂,然后刪掉重新寫
            這樣看起來簡單多了
            用的直接相加求和模大質數的hash
            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            #define maxn 100001
            #define bp 999983
            using namespace std;
            struct node
            {
                
            int x[6];
                
            int next;
            }
             s[maxn],tmp;
            int sec;
            struct node2
            {
                
            int x[6];
                
            void init()
                
            {
                    
            for(int i=0; i<6; i++) scanf("%d",&x[i]);
                }

            }
             a[maxn];
            int n;
            int head[1000001];
            bool flag[1000001];
            int hs;
            inline 
            int hash(node2 t)
            {
                
            return (t.x[0]%bp+t.x[1]%bp+t.x[2]%bp+t.x[3]%bp+t.x[4]%bp+t.x[5]%bp)%bp;
            }

            void add(int hhh,node t)
            {
                s[sec]
            =t;
                s[sec].next
            =head[hhh];
                head[hhh]
            =sec++;
            }

            bool pans(node t1,node t2)
            {
                
            if(t1.x[0]==t2.x[0]&&t1.x[1]==t2.x[1]&&t1.x[2]==t2.x[2]&&t1.x[3]==t2.x[3]&&t1.x[4]==t2.x[4]&&t1.x[5]==t2.x[5]) return 1;
                
            if(t1.x[0]==t2.x[1]&&t1.x[1]==t2.x[2]&&t1.x[2]==t2.x[3]&&t1.x[3]==t2.x[4]&&t1.x[4]==t2.x[5]&&t1.x[5]==t2.x[0]) return 1;
                
            if(t1.x[0]==t2.x[2]&&t1.x[1]==t2.x[3]&&t1.x[2]==t2.x[4]&&t1.x[3]==t2.x[5]&&t1.x[4]==t2.x[0]&&t1.x[5]==t2.x[1]) return 1;
                
            if(t1.x[0]==t2.x[3]&&t1.x[1]==t2.x[4]&&t1.x[2]==t2.x[5]&&t1.x[3]==t2.x[0]&&t1.x[4]==t2.x[1]&&t1.x[5]==t2.x[2]) return 1;
                
            if(t1.x[0]==t2.x[4]&&t1.x[1]==t2.x[5]&&t1.x[2]==t2.x[0]&&t1.x[3]==t2.x[1]&&t1.x[4]==t2.x[2]&&t1.x[5]==t2.x[3]) return 1;
                
            if(t1.x[0]==t2.x[5]&&t1.x[1]==t2.x[0]&&t1.x[2]==t2.x[1]&&t1.x[3]==t2.x[2]&&t1.x[4]==t2.x[3]&&t1.x[5]==t2.x[4]) return 1;
                
            return 0;
            }

            bool pann(node t1,node t2)
            {
                node tmp1;
                
            for(int i=0;i<6;i++) tmp1.x[i]=t1.x[5-i];    
                
            if(tmp1.x[0]==t2.x[0]&&tmp1.x[1]==t2.x[1]&&tmp1.x[2]==t2.x[2]&&tmp1.x[3]==t2.x[3]&&tmp1.x[4]==t2.x[4]&&tmp1.x[5]==t2.x[5]) return 1;
                
            if(tmp1.x[0]==t2.x[1]&&tmp1.x[1]==t2.x[2]&&tmp1.x[2]==t2.x[3]&&tmp1.x[3]==t2.x[4]&&tmp1.x[4]==t2.x[5]&&tmp1.x[5]==t2.x[0]) return 1;
                
            if(tmp1.x[0]==t2.x[2]&&tmp1.x[1]==t2.x[3]&&tmp1.x[2]==t2.x[4]&&tmp1.x[3]==t2.x[5]&&tmp1.x[4]==t2.x[0]&&tmp1.x[5]==t2.x[1]) return 1;
                
            if(tmp1.x[0]==t2.x[3]&&tmp1.x[1]==t2.x[4]&&tmp1.x[2]==t2.x[5]&&tmp1.x[3]==t2.x[0]&&tmp1.x[4]==t2.x[1]&&tmp1.x[5]==t2.x[2]) return 1;
                
            if(tmp1.x[0]==t2.x[4]&&tmp1.x[1]==t2.x[5]&&tmp1.x[2]==t2.x[0]&&tmp1.x[3]==t2.x[1]&&tmp1.x[4]==t2.x[2]&&tmp1.x[5]==t2.x[3]) return 1;
                
            if(tmp1.x[0]==t2.x[5]&&tmp1.x[1]==t2.x[0]&&tmp1.x[2]==t2.x[1]&&tmp1.x[3]==t2.x[2]&&tmp1.x[4]==t2.x[3]&&tmp1.x[5]==t2.x[4]) return 1;
                
            return 0;
            }

            int main()
            {
                scanf(
            "%d",&n);
                
            for(int i=1; i<=n; i++) a[i].init();
                memset(flag,
            0,sizeof(flag));
                memset(head,
            -1,sizeof(head));
                sec
            =0;
                
            bool isex;
                isex
            =false;
                
            for(int i=1; i<=n; i++)
                
            {
                    hs
            =hash(a[i]);
                    
            if(!flag[hs])
                    
            {
                        flag[hs]
            =1;
                        
            for(int j=0; j<6; j++) tmp.x[j]=a[i].x[j];
                        add(hs,tmp);
                    }

                    
            else
                    
            {
                        
            for(int j=0; j<6; j++) tmp.x[j]=a[i].x[j];
                        
            for(int j=head[hs]; j!=-1; j=s[j].next)
                        
            {
                            
            if(pans(tmp,s[j])||pann(tmp,s[j]))
                            
            {
                                isex
            =1;
                                printf(
            "Twin snowflakes found.\n");
                                
            return 0;
                            }

                            
            else 
                            
            {
                                add(hs,tmp);
                            }

                        }

                    }

                }

                
            if(isex==0) printf("No two snowflakes are alike.\n");
                
            return 0;
            }

            posted on 2012-07-24 13:30 jh818012 閱讀(255) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            久久精品国产国产精品四凭| 97热久久免费频精品99| 91精品国产综合久久婷婷| 国产精品99久久久久久宅男小说| 国产—久久香蕉国产线看观看| 秋霞久久国产精品电影院| 国产精品欧美久久久天天影视| 丰满少妇人妻久久久久久| 99久久超碰中文字幕伊人| 久久发布国产伦子伦精品| 久久不见久久见免费视频7| 久久精品aⅴ无码中文字字幕重口| 精品久久久久久亚洲精品| 久久精品国产亚洲精品| 青青久久精品国产免费看| 久久久久无码国产精品不卡| 伊人久久无码精品中文字幕| 久久中文字幕精品| 国产成人久久AV免费| 国产精品久久久久乳精品爆| 尹人香蕉久久99天天拍| 亚洲中文字幕久久精品无码APP| 久久九九精品99国产精品| 国産精品久久久久久久| 久久午夜免费视频| 国内精品久久久久伊人av| 久久精品成人免费国产片小草| 久久国产欧美日韩精品免费| 久久久老熟女一区二区三区| 国产精品热久久无码av| 久久人人爽人人爽人人片AV高清| 国产欧美一区二区久久| 久久综合色之久久综合| 久久精品国产亚洲AV麻豆网站| 精品久久人人妻人人做精品| 麻豆成人久久精品二区三区免费 | 无码人妻久久一区二区三区| 2021久久精品国产99国产精品| 亚洲国产精品成人久久蜜臀| 久久九九有精品国产23百花影院| 久久笫一福利免费导航 |