U E D R , A S I H C RSS

금고/김상섭

로그함수가 이상하당..@,.@

~cpp
#include <iostream>
#include <math.h>
using namespace std;

unsigned int table[501][501];
unsigned int temp_table[2][501];
unsigned int full[10]; 

int calculate(int level, int time)
{
	int value = temp_table[level%2][time];
	if(level > time)
		value = pow(2,time)-1;	
	return value;
}

void process()
{
	int i, j, height, pre_height, time;
	for(i = 1; i <=500; i++)
	{
		table[1][i] = i;
		temp_table[1%2][i]= i;
	}
	for(i = 2; i < 10; i++)
	{
		height = pow(2,i) -1;
		full[i] = height;
		table[i][height] = i;
		temp_table[i%2][i] = height;
		for(time = i +1; height <500 ; time++)
		{
			pre_height = height;
			height = time;
			for(j = 1; j < time; j++)
				height += calculate(i-1,j);
			for(j = pre_height +1; j <= height && j <=500 ; j++)		
				table[i][j] = time;
			temp_table[i%2][time] = height;			
		}		
	}
}

int main()
{
	int height, safe, testnum, i;
	process();

	cin >> testnum;
	for(i = 0; i < testnum; i++)
	{
		cin >> height >> safe;
		if(table[safe][height])
			cout << table[safe][height] << endl;
		else
		{
			for(int j = 2; j < 10; j++)
			{
				if(full[j] > height)
					break;
			}
			cout << j << endl;
		}		
	}	
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:46
Processing time 0.0097 sec