2011年4月16日 星期六

ACM 10038 Jolly Jumpers

本來要寫只開一個陣列的,結果吃了一堆RE,後來又改回開兩個的@@"

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int c[3000];

int main(void)
{
    int n, i, jolly, s;
    bool d[3000];
   
    while (scanf("%d", &n) == 1)
    {
        jolly = 1;
        for (i = 0; i < n; i++)
        {
            d[i] = false;
            scanf("%d", &c[i]);
        }
        for (i = 1; i < n; i++)
        {
            s = abs(c[i] - c[i-1]);
            if (s >= n || s < 1 || d[s])
            {
                jolly = 0;
                printf("Not jolly\n");
                break;
            }
            else
                d[s] = true;
        }
        if (jolly)
            printf("Jolly\n");
    }
   
    return 0;
}

沒有留言:

張貼留言