U E D R , A S I H C RSS

Jolly Jumpers/강�경

~cpp 
#include<iostream>     
using namespace std;    
    
int* InputList();    
bool Judge(int* aList);    
void OutputJudgement(bool aIsIt);    
int GetSumOfGoalGap(int aN);    
 
bool isCorrectInput; 
    
void main()    
{ 
    isCorrectInput = true; 
    OutputJudgement(Judge(InputList()));    
}    
    
int* InputList(){    
    bool isInputStart = false; 
    int numberOfInputFactor; 
    int* inputedList; 
    do{ 
        if(!isInputStart){ 
            if(cin >> numberOfInputFactor){ 
               inputedList = new int[numberOfInputFactor+1]; 
               inputedList[0] = numberOfInputFactor; 
               isInputStart = true; 
                if(numberOfInputFactor < 2){ 
                    isCorrectInput = false; 
                    numberOfInputFactor = 0; 
                } 
           } 
            else{ 
               isCorrectInput = false; 
               numberOfInputFactor = 0; 
           } 
        } 
        else{ 
            if(!(cin >> inputedList[inputedList[0] - numberOfInputFactor])){ 
               isCorrectInput = false; 
               numberOfInputFactor = 0; 
           } 
        } 
        numberOfInputFactor--; 
    }while(numberOfInputFactor >= 0); 
    char temp; 
    cin.get(temp); 
    if(temp != '\n') 
        isCorrectInput = false; 
    return inputedList; 
}    
    
bool Judge(int* aList)   
{    
    if(!isCorrectInput) 
        return false; 
    int gap;    
    bool* binaryMap = new bool[aList[0]-1];    
    for(int i = 0; i < aList[0]-1; i++)    
        binaryMap[i] = false;    
    for(i = 1; i < aList[0]; i++){    
        gap = abs(aList[i] - aList[i+1]); 
        if(gap >= aList[0] || gap == 0 || binaryMap[gap-1]){ 
            delete aList; 
            delete binaryMap; 
            return false; 
        } 
        else      
            binaryMap[gap-1] = true;       
    } 
    delete aList; 
    delete binaryMap;        
    return true;    
}    
    
void OutputJudgement(bool aIsIt)   
{    
    if(aIsIt)    
        cout << "JollyJumpers\n";    
    else    
        cout << "Nothing\n"; 
}    
 

��

성능(performance)� 최�화하기 위해 여러가지 ��� 해보았�.
졸리��임� 확�하는 2가지 조건
1. gap들� �기 다른 �기여야한다.(ex)2가 �번 나오면 안�다.)
  • binaryMapì�´ë�¼ëŠ” bool형 리스트를 사용하여 gapì�˜ 중복ì�„ 검사
2. ��� gap� 0보다 �고 n보다 작아야한다.
시간 복잡�: Ο(n)

ê³ ì¹ ì �

2 2 3 4� 입력� 받는 경우 2 2 3만 ��하여 졸리���고 �단하게 �다. 현재는 고칠 ��없�
그럼 2 2 3 10�서� JollyJumper�고 ��하는 건가?? 그럼 완전 잘못� 거 아�?? --재�
�단 해결!! 예외처리 �분� 코드�서 냄새가 남...리팩토� 해야겠�--강�경

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:34
Processing time 0.0039 sec