맛있는감귤

BOJ : 2839 설탕 배달 본문

알고리즘/백준 알고리즘

BOJ : 2839 설탕 배달

맛있는감귤 2017. 1. 16. 03:56

문제 : https://www.acmicpc.net/problem/2839

github : https://github.com/JEONG-SEUNGWOOK/BOJ/blob/master/2839.cpp


입력 N을 3과 5의 조합으로 만들 수 있는 3,5의 최소 개수의 합을 출력하면 된다. 결국 반복문 문제




#include <stdio.h>
int main(){
    int N,ans=-1;
    scanf("%d",&N);
    bool flag=false;
    for(int i=0; i<=N/3; i++){
        int t=N;
        if((t-(3*i))%5==0) {
            int tt = i+(t-(3*i))/5;
            if(ans == -1) ans = tt;
            else {
                if(ans > tt) ans = tt;
            }
        }
    }
    printf("%d\n",ans);
}


'알고리즘 > 백준 알고리즘' 카테고리의 다른 글

BOJ : 8958 OX게임  (0) 2017.01.16
BOJ : 2577 숫자의 개수  (0) 2017.01.16
BOJ : 1613 역사  (0) 2017.01.15
BOJ : 1600 말이 되고픈 원숭이  (0) 2017.01.15
BOJ : 1389 케빈 베이컨의 6단계 법칙  (0) 2017.01.15