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


[알고리즘풀이]

절반을 기준으로 위 / 아래로 나눠서 구현한다.

#include<iostream>

using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = n - i; j > 0; j--)
			cout << ' ';
		for (int j = 1; j <= i; j++)
			cout << '*';
		cout << '\n';
	}
	for (int i = 1; i < n; i++) {
		for(int j = 0; j < i; j++)
			cout << ' ';
		for (int j = 0; j < n - i; j++)
			cout << '*';
		cout << '\n';
	}
	return 0;

}

 

'Problem Solving > BOJ' 카테고리의 다른 글

[BOJ] 10819 - 차이를 최대로  (0) 2019.09.30
[BOJ] 1520 - 내리막 길  (0) 2019.09.29
[BOJ] 13458 - 시험 감독  (0) 2019.09.29
[BOJ] 2446 - '별 찍기 - 9'  (0) 2019.09.29
[BOJ] 15781 - 헬멧과 조끼  (0) 2019.09.29

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


[알고리즘풀이]

모든 방을 순회하며, 총감독이 감시하는 응시생을 제외한 나머지 응시생들을 부감독 몇명이 감시할 수 있는지

카운트해준다.

#include<iostream>

using namespace std;

int N[1000000];

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> N[i];
	}
	long long b, c, ans = 0;
	cin >> b >> c;

	for (int i = 0; i < n; i++) {
		N[i] -= b;
		ans++;
		if (N[i] > 0) {
			if (N[i] % c == 0)
				ans += (N[i] / c);
			else
				ans += (N[i] / c) + 1;
		}
	}
	cout << ans;
}

 

'Problem Solving > BOJ' 카테고리의 다른 글

[BOJ] 1520 - 내리막 길  (0) 2019.09.29
[BOJ] 2522 - '별 찍기 - 12'  (0) 2019.09.29
[BOJ] 2446 - '별 찍기 - 9'  (0) 2019.09.29
[BOJ] 15781 - 헬멧과 조끼  (0) 2019.09.29
[BOJ] 16486 - 운동장 한 바퀴  (0) 2019.09.29

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


[알고리즘풀이]

역삼각형 부분과 나머지 부분으로 나누어서 구현하면 됩니다.

역삼각형 부분은 총 n 줄이고 ' ' 는 늘어나고,  '*' 는 줄어드고

아래 부분은 총 n - 1 줄이고 ' ' 는 줄어드고, '*' 는 늘어납니다.

#include<iostream>

using namespace std;


int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n;
	// 역삼각형
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++)
			cout << ' ';
		for (int j = 0; j < (2 * n - 1) - 2 * i; j++)
			cout << '*';
		cout << '\n';
	}
	// 나머지부분
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < (n - 1) - i; j++)
			cout << ' ';
		for (int j = 0; j < 2 * i + 1; j++)
			cout << '*';
		cout << '\n';
	}
}

 

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


[알고리즘풀이]

단순 구현 문제입니다.

#include<iostream>

using namespace std;


int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int a, b, m1 = -1, m2 = -1, x;
	cin >> a >> b;
	
	for (int i = 0; i < a; i++) {
		cin >> x;
		if (x > m1)
			m1 = x;
	}
	for (int i = 0; i < b; i++) {
		cin >> x;
		if (x > m2)
			m2 = x;
	}
	cout << m1 + m2;
}

 

'Problem Solving > BOJ' 카테고리의 다른 글

[BOJ] 13458 - 시험 감독  (0) 2019.09.29
[BOJ] 2446 - '별 찍기 - 9'  (0) 2019.09.29
[BOJ] 16486 - 운동장 한 바퀴  (0) 2019.09.29
[BOJ] 16673 - 고려대학교에는 공식 와인이 있다  (0) 2019.09.29
[BOJ] 3896 - Prime Gap  (0) 2019.09.29

+ Recent posts