Baekjoon/C++

[백준 1094번] 막대기

Yo-mi 2023. 10. 8. 03:04
#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