코드의 개요는 다음과 같습니다.
#include <stdio.h>#include <math.h>int n, r, c, cnt = 0;void read(int y, int x, int s) { if (s == 1) { printf("%d\n", cnt); } else { if (r < y + (s / 2)) { if (c < x + (s / 2)) { read(y, x, s / 2); } else { cnt += (s*s) / 4; read(y, x + (s / 2), s / 2); } } else { if (c < x + (s / 2)) { cnt += (s*s) / 2; read(y + (s / 2), x, s / 2); } else { cnt += (s*s) * 3 / 4; read(y + (s / 2), x + (s / 2), s / 2); } } }}int main() { while (true) { cnt = 0; scanf("%d %d %d", &n, &r, &c); read(0, 0, pow(2, n)); }}
기존의 정답자와 코드는 좀 다르지만 푸는 방식은 유사하다고 생각합니다.
그런데 틀렸다는 메세지가 나옵니다.
왜 그러는지 말씀해주실 실력자분 계신가요?
댓글을 작성하려면 로그인해야 합니다.
dyl159 6년 전
코드의 개요는 다음과 같습니다.
#include <stdio.h>
#include <math.h>
int n, r, c, cnt = 0;
void read(int y, int x, int s) {
if (s == 1) {
printf("%d\n", cnt);
}
else {
if (r < y + (s / 2)) {
if (c < x + (s / 2)) {
read(y, x, s / 2);
}
else {
cnt += (s*s) / 4;
read(y, x + (s / 2), s / 2);
}
}
else {
if (c < x + (s / 2)) {
cnt += (s*s) / 2;
read(y + (s / 2), x, s / 2);
}
else {
cnt += (s*s) * 3 / 4;
read(y + (s / 2), x + (s / 2), s / 2);
}
}
}
}
int main() {
while (true) {
cnt = 0;
scanf("%d %d %d", &n, &r, &c);
read(0, 0, pow(2, n));
}
}
기존의 정답자와 코드는 좀 다르지만 푸는 방식은 유사하다고 생각합니다.
그런데 틀렸다는 메세지가 나옵니다.
왜 그러는지 말씀해주실 실력자분 계신가요?