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

感觉该考虑得都考虑到了……可是为什么不过呢?

Posted by analysiser at 2009-07-18 21:44:51 on Problem 2575
//2575  Jolly Jumpers
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int n,num[3001],dif[3000];
    int keep;
    while(cin>>n)
    {

        bool isJolly=true;
        for(int i=1;i<=n;i++)
        {
            cin>>num[i];
            //if(num[i]>=n || num[i]<=0)  isJolly=false;
        }
        for(int i=1;i<=n-1;i++)
        {
            dif[i]=abs(num[i]-num[i+1]);
            //cout<<dif[i]<<endl;
        }
        keep=dif[2]-dif[1];
        for(int i=2;i<=n-2;i++)
        {
            if(keep==1)
            {
                if((dif[i+1]-dif[i])!=1 || dif[n-1]!=n-1)
                {
                    isJolly=false;
                    break;
                }
            }
            else if(keep==-1)
            {
                if((dif[i+1]-dif[i])!=-1 || dif[1]!=n-1)
                {
                    isJolly=false;
                    break;
                }
            }
            else
            {
                isJolly=false;
                break;
            }
        }
        if(isJolly) cout<<"Jolly"<<endl;
        else    cout<<"Not jolly"<<endl;
    }
    system("pause");
    return 0;
}

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