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 rpbear at 2009-11-21 14:30:23 on Problem 2575
顺序是无关紧要的,不管是321还是312都是对的但是不能排序后只看第一个和最后一个是不是1和n-1来判断,因为有可能有331这样的东西,我就是在这里wa很多次啊,附上代码
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>

int compare (const void * a, const void * b)
{
  return ( *(int*)b - *(int*)a );
}

int main(){

    int a[3005],n,m,k=0;
    int length;
    while(scanf("%d",&length)!= EOF){
        int b[length];
        int savelength = length;
        k = 0;
        memset(b,0,length);
        memset(a,0,length);
        while(length-- && scanf("%d",&n)){
            a[k++] = n;
        }
        length = savelength;
        for(k=0;k<length-1;k++)
            a[k] = abs(a[k]-a[k+1]);
        for(k=0;k<length-1;k++)
            b[k] = a[k];

        qsort(a,length-1,sizeof(int),compare);

        if(length != 1)
            if(a[0] == length-1 && a[length-2] == 1){
                bool flag = false;
                for(k=0;k<length-1;k++){
                    if(a[k]+a[length-k-2] != length){
                        printf("Not jolly\n");
                        flag = true;
                        break;
                    }
            }
                if(!flag)printf("Jolly\n");
            }
            else
                printf("Not jolly\n");
        else
            printf("Jolly\n");

    }


	return EXIT_SUCCESS;
}

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