#include <iostream>
using namespace std;
int cut(int x)
{
int stick = 64;
int shortStick = 64;
int n = 1;
while (x < stick)
{
shortStick = shortStick/2;
if (x <= (stick - shortStick))
{
stick -= shortStick;
n--;
}
n++;
}
return n;
}
int main()
{
int x;
cin >> x;
cout << cut(x);
}
문제: https://www.acmicpc.net/problem/1094
1094번: 막대기
지민이는 길이가 64cm인 막대를 가지고 있다. 어느 날, 그는 길이가 Xcm인 막대가 가지고 싶어졌다. 지민이는 원래 가지고 있던 막대를 더 작은 막대로 자른다음에, 풀로 붙여서 길이가 Xcm인 막대
www.acmicpc.net
'Baekjoon > C++' 카테고리의 다른 글
[백준 1181번] 단어 정렬 (0) | 2024.01.08 |
---|---|
[백준 28278번] 스택 2 (0) | 2023.10.06 |
[백준 1018번] 체스판 다시 칠하기 (0) | 2023.09.24 |
[백준 1009번] 분산처리 (0) | 2023.07.25 |
[백준 1012번] 유기농 배추 (0) | 2023.07.25 |