poj3349
来源:互联网 发布:软件操作说明书模版 编辑:程序博客网 时间:2024/05/02 04:41
#include<stdio.h>
#include<malloc.h>
#include<string.h>
typedef struct Node
{
int anxis[6];
struct Node *next;
}Node;
void addNode(Node *data[10000],Node *to_add,int *flag);
void cmp(Node *head,Node *to_add,int *flag);
void cmp(Node *head,Node *to_add,int *flag)
{
//比较head-》的节点和to—add指向的节点
int i;
int j;
int t;
for(i=0; i<6 && !(*flag); i++)
{
j = 0;
if(head->anxis[i] == to_add->anxis[j])
{
t = i;
//顺时针和逆时针处理
while(j<6)
{
if(head->anxis[t] == to_add->anxis[j])
{
t=(t+1)%6,j++;
}
else
{
break;
}
}
if(j==6)
(*flag) = 1;
t = i;
j=0;
while(j<6)
{
if(head->anxis[t] == to_add->anxis[j])
{
t = (t-1<0) ? t+5 : t-1;
j++;
}
else
{
break;
}
}
if(j==6)
(*flag) = 1;
}
}
}
void addNode(Node *data[10000],Node *to_add,int *flag)
{
int i;
int hashNum=0;
Node *head;
Node *pre;
//计算哈希值确定下标
// for(i=0; i<6; i++)
// hashNum = hashNum*7+to_add->anxis[i];
// hashNum = hashNum<0?((-hashNum)%1000):(hashNum%1000);
for(i=0; i<6; i++)
hashNum += to_add->anxis[i];
hashNum = hashNum%10000;
if(data[hashNum] == NULL)
{
data[hashNum] = to_add;
}
else
{
pre = data[hashNum];
head = data[hashNum];
while(head != NULL)
{
//没找到则继续判断
if(!(*flag))
cmp(head,to_add,flag);
pre = head;
head = head->next;
}
pre->next =to_add;
}
}
int main(void)
{
int i,j;
int count;
int flag=0;
Node *data[10000];
Node *t;
memset(data,0,sizeof(Node *)*10000);
scanf("%d",&count);
for(i=0; i<count && (!flag); i++)
{
t = (Node *)malloc(sizeof(Node) * 1);
t->next = NULL;
for(j=0; j<6; j++)
{
scanf("%d",&(t->anxis[j]));
}
addNode(data,t,&flag);
}
if(flag)
printf("Twin snowflakes found.");
else
printf("No two snowflakes are alike.");
}
#include<malloc.h>
#include<string.h>
typedef struct Node
{
int anxis[6];
struct Node *next;
}Node;
void addNode(Node *data[10000],Node *to_add,int *flag);
void cmp(Node *head,Node *to_add,int *flag);
void cmp(Node *head,Node *to_add,int *flag)
{
//比较head-》的节点和to—add指向的节点
int i;
int j;
int t;
for(i=0; i<6 && !(*flag); i++)
{
j = 0;
if(head->anxis[i] == to_add->anxis[j])
{
t = i;
//顺时针和逆时针处理
while(j<6)
{
if(head->anxis[t] == to_add->anxis[j])
{
t=(t+1)%6,j++;
}
else
{
break;
}
}
if(j==6)
(*flag) = 1;
t = i;
j=0;
while(j<6)
{
if(head->anxis[t] == to_add->anxis[j])
{
t = (t-1<0) ? t+5 : t-1;
j++;
}
else
{
break;
}
}
if(j==6)
(*flag) = 1;
}
}
}
void addNode(Node *data[10000],Node *to_add,int *flag)
{
int i;
int hashNum=0;
Node *head;
Node *pre;
//计算哈希值确定下标
// for(i=0; i<6; i++)
// hashNum = hashNum*7+to_add->anxis[i];
// hashNum = hashNum<0?((-hashNum)%1000):(hashNum%1000);
for(i=0; i<6; i++)
hashNum += to_add->anxis[i];
hashNum = hashNum%10000;
if(data[hashNum] == NULL)
{
data[hashNum] = to_add;
}
else
{
pre = data[hashNum];
head = data[hashNum];
while(head != NULL)
{
//没找到则继续判断
if(!(*flag))
cmp(head,to_add,flag);
pre = head;
head = head->next;
}
pre->next =to_add;
}
}
int main(void)
{
int i,j;
int count;
int flag=0;
Node *data[10000];
Node *t;
memset(data,0,sizeof(Node *)*10000);
scanf("%d",&count);
for(i=0; i<count && (!flag); i++)
{
t = (Node *)malloc(sizeof(Node) * 1);
t->next = NULL;
for(j=0; j<6; j++)
{
scanf("%d",&(t->anxis[j]));
}
addNode(data,t,&flag);
}
if(flag)
printf("Twin snowflakes found.");
else
printf("No two snowflakes are alike.");
}
0 0
- poj3349
- poj3349
- POJ3349
- POJ3349
- poj3349
- poj3349
- POJ3349
- POJ3349
- poj3349
- poj3349
- POJ3349
- poj3349
- POJ3349
- poj3349
- POJ3349 哈希表
- POJ3349 #no
- poj3349-hash
- poj3349--Hash
- “生动”讲解——矩阵的空间变换
- 读取配置文件 方式一
- caffe中安装python
- Android中Uri和ContentProvider以及ContentResolver之间的联系
- 9、Java反射(案例)
- poj3349
- 自测题IV——Have Fun with Numbers (20)
- overload override hide
- 数据结构_折半查找
- 脚本拷贝编程
- eclipse如何同时运行两个项目
- 寄语
- 安装spark
- PPT2007版中设置页码及母版格式总解决