C++-POJ3349-Snowflake Snow Snowflakes[STL][set][hash未写]

错误AC解法,sort+set判重,为考虑异构!

比较坑的一点是读入时scanf一定要一次读6个数,不然会TLE

#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct node{
    int a,b,c,d,e,f,hash;
    node(int a,int b,int c,int d,int e,int f):a(a),b(b),c(c),d(d),e(e),f(f){}
    bool operator<(const node&x)const{
        if(a==x.a&&b==x.b&&c==x.c&&d==x.d&&e==x.e)return f<x.f;
        if(a==x.a&&b==x.b&&c==x.c&&d==x.d)return e<x.e;
        if(a==x.a&&b==x.b&&c==x.c)return d<x.d;
        if(a==x.a&&b==x.b)return c<x.c;
        if(a==x.a)return b<x.b;
        return a<x.a;
    }
};
set<node>s;
int n,l[6];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d%d%d%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5]),sort(l,l+6);
        node snow=node(l[0],l[1],l[2],l[3],l[4],l[5]);
        if(s.find(snow)!=s.end()){puts("Twin snowflakes found.");return 0;}
        s.insert(snow);
    }
    puts("No two snowflakes are alike.");
    return 0;
}

原文地址:https://www.cnblogs.com/JasonCow/p/12304569.html

时间: 2024-11-02 10:15:56

C++-POJ3349-Snowflake Snow Snowflakes[STL][set][hash未写]的相关文章

[poj3349]Snowflake Snow Snowflakes(hash)

Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 37615 Accepted: 9882 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

POJ3349 Snowflake Snow Snowflakes (hash

Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 48624   Accepted: 12697 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.

Hash poj3349 Snowflake Snow Snowflakes

题意:判断是否有两片一样的雪花. Hash第一题,基本是抄的. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

POJ3349: Snowflake Snow Snowflakes(hash 表)

考察hash表: 每一个雪花都有各自的6个arm值,如果两个雪花从相同或者不同位置开始顺时针数或者逆时针数可以匹配上,那么这两个雪花就是相等的. 我们采用hash的方法,这样每次查询用时为O(1),总用时为O(n). hash的本质是把值映射到地址或者下标,如果不同的key值对应到相同的indice上的话,就需要进行chaining处理,吧indice指向一个链表,链表的每一个节点存储共享同一indice的不同key值. 因此问题的核心变成:吧相等的雪花映射到相同的indice上.这里雪花是一个

POJ3349 Snowflake Snow Snowflakes

Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 39075   Accepted: 10232 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 inf

POJ3349 Snowflake Snow Snowflakes 【哈希表】

题目 很简单,给一堆6元组,可以从任意位置开始往任意方向读,问有没有两个相同的6元组 题解 hash表入门题 先把一个六元组的积 + 和取模作为hash值,然后查表即可 期望\(O(n)\) #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #define LL long long int #define Redge(

POJ3349 Language: Snowflake Snow Snowflakes

POJ3349 Language: Snowflake Snow Snowflakes 题目:传送门 题解: 链表+hash的一道水题 填个坑补个漏... 代码: 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 typedef long long L

hash应用以及vector的使用简介:POJ 3349 Snowflake Snow Snowflakes

今天学的hash.说实话还没怎么搞懂,明天有时间把知识点总结写了,今天就小小的写个结题报告吧! 题意: 在n (n<100000)个雪花中判断是否存在两片完全相同的雪花,每片雪花有6个角,每个角的长度限制为1000000 两片雪花相等的条件: 雪花6个角的长度按顺序相等(这个顺序即可以是顺时针的也可以是逆时针的) 解题思路: hash:连加求余法 求key 值,链地址法解决冲突,连加求余法 求key 值挺简单,关于链地址法解决冲突可以通过c++中,vector容器可以较为方便的实现. 下面先介绍

POJ 3349:Snowflake Snow Snowflakes(数的Hash)

http://poj.org/problem?id=3349 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 37609   Accepted: 9878 Description You may have heard that no two snowflakes are alike. Your task is to write a program to determine