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

哪位帮我看看代码啊,我觉得没问题,可就是 WA

Posted by wc227 at 2010-04-15 22:38:26 on Problem 2575
#include<iostream>
#include<math.h>
#define N 3000
using namespace std;

int main()
{
    int n,i,j;
    int a[N],index[N];
    while(cin>>n)
    {
                 if(n==1)
                 {
                         cout<<"Jolly"<<endl;
                         continue;
                         }
                 else
                 {
                     i=0;
                     while(i<n)
                     {
                               cin>>a[i];
                               index[i]=0;
                               ++i;
                               }
                               i=0;
                               while(i<n-1)
                               {
                                           j=abs(a[i]-a[i+1]);
                                           if(j>=n||index[j]==1)
                                           {
                                                                cout<<"Not jolly"<<endl;
                                                                break;
                                                                }
                                                                index[j]=1;
                                                                ++i;
                                           }
                                           if(i==n-1)cout<<"Jolly"<<endl;
                     }
                 }
          return 0;     
    }
我的想法很简单,用一个指标数组来指示1到n-1的数哪些已经用过了,如果重复出现,则不是;如果能执行到最后,则是

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