10038

題目:http://luckycat.kshs.kh.edu.tw/homework/q10038.htm
觀念:bruteforce (DFS)
難度:luckycat ★

#include <iostream>
#include <string.h>
using namespace std; 
int N, input[3005];
bool used[3005];
int main(){

    while ( cin >> N ){

        bool isJolly = true;

        for ( int i = 0 ; i < N ; i++ ){
            used[i] = false;
            cin >> input[i];
        }

        for ( int i = 1 ; i < N ; i++ ){
            int offset = abs( input[i] - input[i-1] );
            if ( offset > 0 && offset < N ){
                // 如果該距離已存在,代表不符合jolly格式    
                if ( !used[offset] )
                    used[offset] = true;
                else{
                    isJolly = false;
                    break;    
                }    
            }
            else{
                isJolly = false;
                break;
            }
        }

        if ( isJolly )
            cout << "Jolly" << endl;
        else
            cout << "Not jolly" << endl;
    }
    return 0;        
}

results matching ""

    No results matching ""