Thursday, November 10, 2016

BFS

public class NovFifth {

    public static void main(String args[]){
        int a = 10;
        int b = 100;
        
        String inputOperation1 = "*2";
        String inputOperation2 = "*3";
        String inputOperation3 = "+1";
        
        char[] operations1 = inputOperation1.toCharArray();
        char[] operations2 = inputOperation2.toCharArray();
        char[] operations3 = inputOperation3.toCharArray();
        
        char operator1 = operations1[0];
        int operand1 = Character.getNumericValue(operations1[1]);
        char operator2 = operations2[0];
        int operand2 = Character.getNumericValue(operations2[1]);
        char operator3 = operations3[0];
        int operand3 = Character.getNumericValue(operations3[1]);
        
        Operation[] operationArray = new Operation[3];
        Operation Operation1 = new Operation(operator1, operand1);
        Operation Operation2 = new Operation(operator2, operand2);
        Operation Operation3 = new Operation(operator3, operand3);
        operationArray[0] = Operation1;
        operationArray[1] = Operation2;
        operationArray[2] = Operation3;
        
        
        
        Node startPoint = new Node();
        Node start = new Node();
        start.level = 0;
        start.number = a;
        startPoint = start;
        
        Node endPoint = new Node();
        endPoint = start;
        
        Node currentNode = start;
        
        int minimunLength = 0;
        while(true){
            boolean answerFlag = false;
            int currentLevel = currentNode.level;
            
            for(int i=0; i<3; i++){
                Operation op = operationArray[i];
                int answer = calc(currentNode.number, op.operator, op.operand);
                if(answer == b){
                    answerFlag = true;
                    minimunLength = currentLevel + 1;
                }else if(answer < b){
                    //Push Queue
                    Node node  = new Node();
                    node.level = currentLevel  + 1;
                    node.number = answer;
                    endPoint.next = node;
                    endPoint = endPoint.next;
                }
            }
            
            if(answerFlag){
                break;
            }
            
            //Pop Queue
            currentNode = startPoint;
            startPoint = startPoint.next;
            
        }
        printQueue(startPoint);
        System.out.println("Answer : "+minimunLength);
        
    }
    
    public static int calc(int current, char operator, int operand){
        int returnNum = 0;
        if(operator == '*'){
            returnNum = current * operand;
        }else{
            returnNum = current + operand;
        }
        
        return returnNum;
    }
    
    public static void printQueue(Node node){
        int count = 0;
        while(true){
            //System.out.print(node.number+" ");
            if(node.next == null){
                break;
            }else{
                node = node.next;
                count++;
            }
        }
    }    
}

class Operation{
    public char operator;
    public int operand;
    public Operation(char operator, int operand){
        this.operator = operator;
        this.operand = operand;
    }
    
}

class Node{
    int number;
    int level;
    Node next;
}

Thursday, October 27, 2016

청첩장 무료 샘플 제공 사이트 소개

카드마켓 (http://www.card-market.co.kr/) 


- 다른 청첩장 제공 사이트가 배송비를 요구하는데 비해 무료로 샘플을 제공한다는 점에저 장점 (From&To, http://www.wfromnto.co.kr/ 의 경우 샘플 신청을 하였으나 2,500원 배송비 지불)

- 카드마켓이 From&To에비해 |1~20,000원 정도 비싸기는 하지만 청첩장 퀄리티나 완성도,추가 서비스(액자, 할인 쿠폰 제공, 추가 샘플 제공, 모바일 무료 청첩장 등) 등 다른 모든 면에서 월등히 앞선다고 판단됨.




카드마켓에서 무료로 제공된 샘플 청첩장

Thursday, October 20, 2016

DFS Example


public class DFSExample {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int[][] conn = { { 0, 1, 0, 1, 0, 0, 0, 0, 1 }, // 0
                        { 0, 0, 0, 0, 0, 0, 0, 1, 0 }, // 1
                        { 0, 0, 0, 0, 0, 1, 0, 0, 0 }, // 2
                        { 0, 0, 1, 0, 1, 0, 0, 0, 0 }, // 3
                        { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 4
                        { 0, 0, 0, 0, 0, 0, 1, 0, 0 }, // 5
                        { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 6
                        { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 7
                        { 0, 0, 0, 0, 0, 0, 0, 0, 0 } };// 8
        
        
        boolean[] visited = new boolean[conn.length];
        int v = 0;
        
        DFS(conn, visited, v);
    }
    
    public static void DFS(int[][] conn, boolean[] visited, int v){
        visited[v] = true;
        System.out.println("nextNode : "+v);
        
        for(int i = 0; i < visited.length; i++){
            if(conn[v][i] > 0 && !visited[i]){
                DFS(conn, visited, i);
            }
        }
    }

}

BFS Exmaple

import java.util.LinkedList;
import java.util.Queue;

public class BFSExample {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int[][] conn = { { 0, 1, 0, 1, 0, 0, 0, 0, 1 }, // 0
                { 1, 0, 0, 0, 0, 0, 0, 1, 0 }, // 1
                { 0, 0, 0, 1, 0, 1, 0, 1, 0 }, // 2
                { 1, 0, 1, 0, 1, 0, 0, 0, 0 }, // 3
                { 0, 0, 0, 1, 0, 0, 0, 0, 1 }, // 4
                { 0, 0, 1, 0, 0, 0, 1, 0, 0 }, // 5
                { 0, 0, 0, 0, 0, 1, 0, 0, 0 }, // 6
                { 0, 1, 1, 0, 0, 0, 0, 0, 0 }, // 7
                { 1, 0, 0, 0, 1, 0, 0, 0, 0 } };// 8

        BFS(conn);
    }

    public static void BFS(int[][] conn) {
        Queue q = new LinkedList();
        
        boolean[] visited = new boolean[conn.length];
        
        for(int i = 0; i < visited.length; i++){
            visited[i] = false;
        }
        
        q.add(0);
        
        while(!q.isEmpty()){
            int nextNode;
            int i;
            nextNode= (int) q.remove();
            
            if(!visited[nextNode]){
                visited[nextNode] = true;
                System.out.println("nextNode = "+ nextNode);
                for(i = 0; i < visited.length; i++){
                    if(conn[nextNode][i] > 0 && !visited[i]){
                        q.add(i);
                    }
                }
            }
        }
        
    }
}

Sunday, October 18, 2015

주사위

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.*;

public class Main {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  Scanner sc = new Scanner(System.in);
  
  int N1 = sc.nextInt();
  int N2 = sc.nextInt();
  int N3 = sc.nextInt();
  
  int Size = N1 * N2 * N3;
  int[] answerArray = new int[Size];
  
  int answerIdx = 0;
  for(int i=1; i<=N1; i++){
   
   for(int j=1; j<=N2; j++){
    
    for(int k=1; k<=N3; k++){
     answerArray[answerIdx++] = i + j + k;
    }
   }
  }
  
  Arrays.sort(answerArray);
  
  int currentNum = answerArray[0];
  int maxNum = answerArray[0];
  int currentCnt = 1;
  int maxCnt = 1;
  
  for(int i=1; i<answerArray.length; i++){
   if(currentNum != answerArray[i]){
    if(maxCnt < currentCnt){
     maxNum = currentNum;
     maxCnt = currentCnt;
    }
    currentNum = answerArray[i];
    currentCnt = 1;
    
   }else{
    currentCnt++;
   }
   
  }
  
  System.out.println(maxNum);

 }


}

수학귀신

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.*;

public class Main {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  Scanner sc = new Scanner(System.in);
  
  int K = sc.nextInt();
  
  long[] zeroCntArray = new long[K+1];
  long[] oneCntArray = new long[K+1];
  
  int i = 0;
  zeroCntArray[i] = 0;
  oneCntArray[i++] = 0;
  
  zeroCntArray[i] = 0;
  oneCntArray[i++] = 1;
  
  if(K >= 2){
   zeroCntArray[i] = 1;
   oneCntArray[i++] = 1;
   
   for(; i<K+1; i++){
    zeroCntArray[i] = zeroCntArray[i-1] + zeroCntArray[i-2];
    oneCntArray[i] = oneCntArray[i-1] + oneCntArray[i-2];
   }
  }
  
  System.out.println(zeroCntArray[K]+" "+oneCntArray[K]);

 }


}

창고다각형

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.*;

public class Main {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  Scanner sc = new Scanner(System.in);
  
  int N = sc.nextInt();
  int[][] inputArray = new int[N][2];
  
  for(int i=0; i<N; i++){
   inputArray[i][0] = sc.nextInt();
   inputArray[i][1] = sc.nextInt();
  }
  
  sort(inputArray);
  
  int maxHeightIndex = 0;
  int maxHeight = inputArray[0][1];
  for(int i=0; i<N; i++){
   
   if(inputArray[i][1] > maxHeight){
    maxHeightIndex = i;
    maxHeight = inputArray[i][1];
   }
   
  }
  
  System.out.println(maxHeightIndex+" "+maxHeight);
  
  int currentHeight = inputArray[0][1];
  for(int i=0;i<maxHeightIndex;i++){
   
  }
  
 }
 
 
 static void sort(int[][] inputArray){
  
  for(int i=0; i<inputArray.length - 1; i++){
   
   for(int j=i; j<inputArray.length - 1; j++){
    
    if(inputArray[j][0] > inputArray[j+1][0]){
     int tempLocation = inputArray[j][1];
     inputArray[j][1] = inputArray[j+1][1];
     inputArray[j+1][1] = tempLocation;
     
     int tempHieght = inputArray[j][0];
     inputArray[j][0] = inputArray[j+1][0];
     inputArray[j+1][0] = tempHieght;
     
    }
   } 
  }

 }

}