-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
6-wnsmir #26
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λΈλ£¨νΈν¬μ€λ‘ λΆλ₯λ λ¬Έμ λΌμ μ¬μ΄κ±΄μ€ μμλλ° μλλ€μ..
λ§μμμΌλ‘ λΈλ£¨νΈν¬μ€λ μ½μ§ λΌλ μκ°μ΄ μμλλ°,
μ‘°κΈ λ°μ±νκ² λλ λ¬Έμ μ
λλ€...
μ΄λ€ κ²μ κΈ°μ€μΌλ‘ λΈλ£¨νΈν¬μ€ ν΄μΌν μ§ κ°μ΄ μμ‘νμ μ€μ©λ μ½λ λ΄€μ΅λλ€.
κ°λ₯ν λμ΄λ₯Ό 0~256μΌλ‘ μ‘λ κ²μ μμκ³ ,
μ§μ ꡬνν΄λ³΄μμ΅λλ€.
κ°λ₯ν λμ΄λ₯Ό κΈ°μ€μΌλ‘ λΈλ£¨νΈν¬μ€λ‘ κ²μνλ€λ κ²μ μκ²λλκΉ,
κ·Έλλ λλ¦ μ ν리λκ΅°μ.
μ΄λ² λ¬Έμ λ₯Ό νλ©΄μ λΈλ£¨νΈν¬μ€ν λ³μ κ°μ κ²μ μ μ νλ κ²μ΄ μ€μνλ€λ κ²μ μκ²λμμ΅λλ€.
μ’μ λ¬Έμ κ°μ¬ν©λλ€.
μ½λλ μλμ κ°μ΅λλ€.
(μ½λλ₯Ό μ΄μ§μ΄μ§ 리ν©ν λ§νλλ° κ²°κ΅ μ€μ©λ μ½λλ μμ ν λΉμ·ν΄μ Έλ²λ Έλ€μ...)
CPP CODE
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
#define PLACE 1
#define REMOVE 2
using namespace std;
int main() {
int N, M, B;
cin >> N >> M >> B;
vector<vector<int>> field(N, vector<int>(M));
for (int y = 0; y < N; y++)
for (int x = 0; x < M; x++)
cin >> field[y][x];
int bestHeight = 0;
int minTime = INT_MAX;
int height = -1;
while (height++ < 257) {
int remove = 0;
int place = 0;
for (int y = 0; y < N; y++) {
for (int x = 0; x < M; x++) {
int diff = field[y][x] - height;
if (diff > 0) remove += diff;
else place -= diff;
}
}
if (remove + B >= place) {
int time = remove * REMOVE + place * PLACE;
minTime = min(time, minTime);
if (time == minTime && height > bestHeight)
bestHeight = height;
}
}
cout << minTime << ' ' << bestHeight;
return 0;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ§€λ² μ¬λ°λ λ¬Έμ λ₯Ό κ°μ Έμ€μλκ±° κ°λ€μ ! μ΄λ² λ¬Έμ λ λκ° νλ¦΄λ― λ§λ―ν΄μ λκΉμ§ μ§μνκ² νμ΄λ΄€μ΅λλ€. 1μκ°μ΄ μ’ λκ² κ±Έλ Έλ€μ
λ¬Έμ λ₯Ό 보면 λ΅μ΄ μ¬λ¬κ°λΌλ©΄ κ°μ₯ λμ λμ΄λ₯Ό κ³ λ₯Έλ€.
κ° μλλ° μ²¨μ 무μ¨λ§μΈμ§ λͺ°λΌμ κ·Έλ₯ λ겨λ²λ Έλλ° μ΄κ² λλ¬Έμ 30λΆμ λ μ΄ κ±° κ°μμ. μ€μ©λ μ½λλμ μ κ·Όμ΄ λ§μ΄ λ¬λΌμ μ΄ν΄νκΈ° μ΄λ €μΈκ±° κ°μ μ£Όμμ μ’ λ¨κΈ°κ² μ΅λλ€.!
code
#include <iostream>
#include <climits>
using namespace std;
#define MAX 500
int map[MAX][MAX] = { 0, };
int baseMap[MAX][MAX] = { 0, };
int n, m, b;
int t = 0;
int tmp, inven;
int minHeight = INT_MAX;
int height = INT_MIN, timeTaken = INT_MAX;
bool isFlat() {
int k = baseMap[0][0];
for (int y = 0; y < m; y++) {
for (int x = 0; x < n; x++) {
if (k != baseMap[y][x]) return false;
}
}
return true;
}
// ν μΈ΅μ μ¬λ €κ°λ©΄μ μκ°μ μ€μ νκ³ μΈλ²€ν 리μμ itemμ λΊλ€.
void update() {
for (int y = 0; y < m; y++) {
for (int x = 0; x < n; x++) {
if (map[y][x] > baseMap[y][x]) t -= 2;
else t += 1;
baseMap[y][x]++;
inven--;
}
}
}
void read() {
for (int y = 0; y < m; y++) {
for (int x = 0; x < n; x++) {
cin >> tmp;
map[y][x] = tmp;
inven += tmp;
t += tmp * 2;
if (minHeight > tmp) minHeight = tmp;
}
}
}
int main() {
//μΈλ²€ν 리μ ν¬κΈ°λ 64,000,000 = 500 x 500 x 256 μμ μ μνμ!
//λͺ¨λ λΈλμ λ€ λΉΌκ³ μλ μλ μ리μ λ£μΌλ©΄ μκ°μ +1μ΄ μλλΌ -2μ΄λ€.
//isFlatνλ©΄ μ΅μ μκ°μ μ΄κΈ°ννλ€.
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> b;
inven = b;
read();
//minHeightλΆν° νμΈ΅μ© μμ μ¬λΌκ°
for (int y = 0; y < m; y++) {
for (int x = 0; x < n; x++) {
baseMap[y][x] = minHeight;
t -= minHeight * 2;
inven -= minHeight;
}
}
while (inven >= 0) {
if (isFlat()) {
if (t >= 0 && timeTaken > t || timeTaken == t && height < baseMap[0][0]) {
timeTaken = t;
height = baseMap[0][0];
}
if (inven == 0) break;
}
update();
}
cout << timeTaken << ' ' << height;
return 0;
}
# κ°λ₯ν λμ΄ hλ₯Ό 0μμ 256κΉμ§ μν | ||
for h in range(257): | ||
remove_blocks = 0 | ||
add_blocks = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄λ κ² λ§€λ² κ°λ₯ν λμ΄μ λν΄μλ§ μ°μ°μ νλ©΄ mapμ΄ flatνμ§ κ²μ¬λ₯Ό μν΄λ λλ€μ. μμ² ν¨μ¨μ μΈ μ½λμΈ κ² κ°μ΅λλ€.. μμ΄λμ΄ λλ°..
if remove_blocks + B >= add_blocks: | ||
time = remove_blocks * 2 + add_blocks | ||
# μ΅μ μκ° κ°±μ λ° μ΅λ λμ΄ μ ν | ||
if time < min_time or (time == min_time and h > best_height): | ||
min_time = time | ||
best_height = h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ λ μ¬κΈ°μ ifμ€μ²©μ΄ μμ² λ§μλλ° μμ ν΄μΌκ² λ€μγ
π λ¬Έμ λ§ν¬
https://www.acmicpc.net/problem/18111
βοΈ μμλ μκ°
1h
β¨ μλ μ½λ
μ μΌ λ¨Όμ ν΄μΌν μμ μ λμ΄μ€μ μ λλ€.
μ²μμ λ¨μνκ² μ μΌ λ§μ΄ λμ¨ landκ°μ΄ μ΅μ μ λμ΄λΌκ³ μκ°νλλ°
222
223
333
κ°μ κ²½μ°μ 2κ° κ°μ₯ λ§μ κ²½μ°μ μμ§λ§, 3μΌλ‘ λ§μΆλ©΄ 5κ°λ§ μ¬λ €μ£Όλ©΄ λκΈ° λλ¬Έμ
μ¬λ¦΄λμ μκ° 1μ΄ * 5 -> 5μ΄
2λ‘ λ§μΆλ€λ©΄ 2μ΄ * 4 -> 8μ΄
μ¦ 3μ΄ μ΅μ μ λμ΄κ° λ©λλ€.
λ°λΌμ λΈλ£¨νΈν¬μ€λ‘ λ¬Έμ λ₯Ό νΈλκ²μ΄ κ°μ₯ μ ν©νλ€κ³ κ²°λ‘ λ΄λ Έμ΅λλ€.
λΈλ£¨νΈν¬μ€λ κ° λμ΄μ λν΄ μ§νν΄μ€λλ€. μ¦ μ΅μ μ λμ΄λ₯Ό μ ν΄λκ³ ,
μ§νμ λͺ¨λ μ’νλ₯Ό μννλ©° νμ¬ λμ΄μ λͺ©νλμ΄μ μ°¨λ₯Ό μ΄μ©ν΄ μΈλ²€ν 리μ λ€μ΄κ°μ§, μΈλ²€ν 리μμ λΊμ§λ₯Ό μ νκ³ , κ·Έμλ°λ₯Έ μκ°λ μ λ°μ΄νΈν΄μ€λλ€.
μ΄ κ³Όμ μμ μ΄κΈ° μΈλ²€ν 리 λΈλ‘ μ + μ κ±°ν λΈλ‘ μ - μΆκ°ν λΈλ‘ μ κ° μμκ° λμ¨λ€λ©΄ κ·Έ λ¨κ³μ λμ΄λ λΆκ°λ₯νκΈ° λλ¬Έμ λ€μλ¨κ³λ‘ λμ΄κ°λλ€.
μ¬κΈ°μ κ°μ₯ μμ μκ°μΌλ‘ μ λ°μ΄νΈ ν λμ λμ΄λ₯Ό μ΅μ μ λμ΄λ‘ μ€μ νκ³ λ§μ½ μκ°μ΄ κ°μλ©΄, λμ΄λ§ μ λ°μ΄νΈ ν΄μ€λλ€.