본문 바로가기

algorithm

2110,2447

//2447
#include <iostream>
using namespace std;
int k;
char map[7000][7000];
void sol(int i,int j,int sz){
	if(sz == 1){
		map[i][j] = '*';
		return;
	}
	int nsz = sz/3;
	for(int m = i; m < i + sz; m += nsz){
		for(int n = j; n < j+ sz; n += nsz){
			if(m == i + nsz && n == j + nsz) continue;
			  sol(m,n,nsz);
	}	
	}
}
int main() {
	cin>>k;
	sol(0,0,k);
	for(int i = 0; i < k; i++){
		for(int j = 0; j < k; j++){
			if(map[i][j] != '*') map[i][j] = ' ';
			cout<<map[i][j];
		}
		cout<<'\n';
	}
	return 0;
}
//2110
#include <iostream>
#include <algorithm>
using namespace std;
int N,C;
int A[200010];
bool sol(int mid){
	int n = 0, t = 0;
		for(int i = 1; i < N; i++){
			if(A[i] - A[i-1] + t >= mid) {
				n++;
				t = 0;
			}
			else t += A[i] - A[i-1];
		}
		if(n + 1 >= C) return true;
		else return false;
}
int main() {
	cin>>N>>C;
	for(int i = 0; i < N; i++) cin>>A[i];
	sort(A,A+N);
	int s = 0, e = A[N-1] - A[0], mid = 0;
	while(s <= e){	
		mid = (s+e)/2;
		if(sol(mid)) s = mid + 1;
		else e = mid -1;
	}
	cout<< e;
	return 0;
}

'algorithm' 카테고리의 다른 글

2213  (0) 2022.05.20
2533  (0) 2022.05.19
1450 로봇청소기  (0) 2022.05.16
16888 루트 게임  (0) 2022.05.15
15877  (0) 2022.05.14