你这代码写的...让我眼花缭乱
首先,你的hash[]数组重定义了,C++保留字有hash,你把它改成别的,例如hashdef
还有,你的freopen函数写的不安全,肯定会提示unsafe
要在代码前面加上#pragma warning(disable:4996)
例如:
#include "stdafx.h"
#include
#include
#include
#pragma warning(disable:4996)
#define prime 9999991
这样整个程序就没问题,我已经编译通过。
//3349 Accepted 3684K 1969MS C++ 727B 2017-03-01 16:33:42
#include
#include
#include
using namespace std;
const int MAX=149993;
int h[MAX][6], n;
int locate(int t[]){
inti, key = 0;
for(i=0; i<6; i++)
key += t[i]*(i+1); //写成key += t[i]就超时了
i= key%MAX;
while(h[i][0] != -1 && memcmp(t, h[i], sizeof(int)*6) != 0) i=(i+1)%MAX;
return i;
}
int main()
{
freopen("data.in","r", stdin);
//freopen("data.out","w", stdout);
inta[6], i, j, pos;
boolfound = false;
scanf("%d",&n);
memset(h,-1, sizeof(h));
while(n--){
for (i=0; i<6; i++)
scanf("%d",&a[i]);
for (i=0; i<6; i++)
for(j=i+1; j<6; j++)
if (a[i]>a[j]) a[i] ^= a[j] ^= a[i] ^=a[j];
pos = locate(a);
if (h[pos][0] == -1) memcpy(h[pos], a,sizeof(int)*6);
else {
found= true;
break;
}
}
if(found) printf("Twin snowflakes found.");
elseprintf("No two snowflakes are alike.");
return0;
}