Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

wrong answer 大家帮忙看一下

Posted by bird1015 at 2010-11-01 10:16:05 on Problem 3349
#include<stdio.h>
#define MAX 100000
#define Prime 14997
int hash_table[MAX] = {0};
int main()
{
    int n,i,j,a[6],sum0,sum1,loc,flag1=0;
    scanf("%d",&n);
    for(i = 0; i < n; i++)
    {
        sum0 = 0;
        sum1 = 0;
        loc = 0;
        for(j = 0; j < 6; j++)
           a[j] = 0;
        for(j = 0; j < 6; j++)
        {
            scanf("%d",&a[j]);
            if(j != 0)
            {
                 if(a[j] - a[j - 1] >= 0)
                    sum0 += a[j] - a[j - 1] ;
                 else
                    sum0 += -(a[j] - a[j - 1]);
            }
            sum1 += a[j]; 
        }
        if(a[j - 1] - a[0] >= 0)
        sum0 += a[j - 1] - a[0];
        else
        sum0 += -(a[j - 1] - a[0]);
         loc = (sum0 % Prime + sum1) % MAX;
      if(hash_table[loc])
      {
          flag1 = 1;
      }  
      else
      hash_table[loc] = 1;
    }
     if(flag1)     
      printf("Twin snowflakes found.");
     else
      printf("No two snowflakes are alike.");
    getchar();
    getchar();
    return 0;
}
//算法思想:为了确定顺序,使用相邻的两个数字相减(首尾也相减)取正数求和得出结果sum0和总共六个分支求和得到的数据sum1一起来计算hash地址  loc = (sum0 % Prime + sum1) % MAX; 
//但是在提交的时候却是wrong answer 
自己测试的时候没问题,也测试了一下之前几位前辈提供的测试数据也没问题

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator