Skip to content
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

12-SeongHoonC #45

Merged
merged 3 commits into from
Mar 5, 2024
Merged

12-SeongHoonC #45

merged 3 commits into from
Mar 5, 2024

Conversation

SeongHoonC
Copy link
Collaborator

@SeongHoonC SeongHoonC commented Feb 29, 2024

πŸ”— 문제 링크

λΆ„ν•  정볡 ν•œ 번 더 μ •λ³΅ν•˜κΈ°
색쒅이 λ§Œλ“€κΈ°

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

40λΆ„

✨ μˆ˜λ„ μ½”λ“œ

ν˜„μž¬ λ²”μœ„ λ‚΄ 쒅이가 μ „λΆ€ νŒŒλž€μƒ‰μΈμ§€ ν•˜μ–€μƒ‰μΈμ§€ κ²€μ‚¬ν•©λ‹ˆλ‹€.

  • λ‘˜ 쀑 ν•˜λ‚˜λΌλ©΄ κ·Έ 색쒅이 숫자λ₯Ό +1 ν•˜κ³  ν•¨μˆ˜λ₯Ό μ’…λ£Œν•©λ‹ˆλ‹€.
  • λ‘˜ 쀑 μ–΄λŠν•˜λ‚˜λ„ μ•„λ‹ˆλΌλ©΄ 쒅이λ₯Ό 1, 2, 3, 4 λΆ„λ©΄μœΌλ‘œ λ‚˜λˆ„μ–΄ μž¬κ·€λ₯Ό μ‹€ν–‰ν•©λ‹ˆλ‹€.
var blue = 0
var white = 0
fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    val paper = Array(n) { Array(n) { 0 } }

    for (i in 0 until n) {
        val line = br.readLine().split(" ").map { it.toInt() }
        for (j in 0 until n) {
            paper[i][j] = line[j]
        }
    }

    // μž¬κ·€ ν•¨μˆ˜ μ‹€ν–‰
    cut(0, 0, n, paper)
    println(white)
    println(blue)
}

private fun cut(x: Int, y: Int, n: Int, paper: Array<Array<Int>>) {
    // λͺ¨λ‘ 1이면 νŒŒλž‘ +1 ν›„ return
    //λͺ¨λ‘ 0이면 ν•˜μ–‘ + 1 ν›„ return
    if (checkPaper(x = x, y = y, n = n, paper = paper, target = 1) { blue++ }) return
    if (checkPaper(x = x, y = y, n = n, paper = paper, target = 0) { white++ }) return

    // n 을 2둜 λ‚˜λˆ„μ–΄ 1, 2, 3, 4 λΆ„λ©΄ μž¬κ·€λ‘œ μ‹€ν–‰
    val divN = n / 2
    cut(x, y, divN, paper)
    cut(x + divN, y, divN, paper)
    cut(x, y + divN, divN, paper)
    cut(x + divN, y + divN, divN, paper)
}

private fun checkPaper(x: Int, y: Int, n: Int, paper: Array<Array<Int>>, target: Int, action: () -> Unit): Boolean {
    val isSame = (x until x + n).all { dx -> (y until y + n).all { dy -> paper[dx][dy] == target } }
    if (isSame) {
        action()
        return true
    }
    return false
}

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@alstjr7437
Copy link
Member

image

μ €λŠ” μ˜ˆμ „μ— java둜 ν‘Ό μ½”λ“œκ°€ μžˆμ—ˆμŠ΅λ‹ˆλ‹€!!
λ”°λ‘œ λŒμ•„κ°€λŠ” λ‘œμ§μ€ kotlinκ³Ό λ˜‘κ°™μ€ 것 κ°™λ„€μš”!
λ‹€μ‹œλ³΄λ‹ˆκΉŒ 저도 n/2λ₯Ό ν•΄λ†¨λ„€μš” γ„·γ„·
생각보닀 μ½”λ“œκ°€ 많이 λΉ„μŠ·ν•΄μ„œ μ‹ κΈ°κ΅°μš”!!

import java.util.Scanner;
 
 
public class Main {
	
	public static int white = 0;
	public static int blue = 0;
	public static int[][] board;
 
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		
		board = new int[N][N];
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				board[i][j] = in.nextInt();
			}
		}
		
		partition(0, 0, N);
		
		System.out.println(white);
		System.out.println(blue);
		
	}
	
	public static void partition(int row, int col, int size) {
		
		if(colorCheck(row, col, size)) {
			if(board[row][col] == 0) {
				white++;
			}
			else {
				blue++;
			}
			return;
		}
		
		int newSize = size / 2;	
		partition(row, col, newSize);						
		partition(row, col + newSize, newSize);				
		partition(row + newSize, col, newSize);				
		partition(row + newSize, col + newSize, newSize);	
	}
	
	
	public static boolean colorCheck(int row, int col, int size) {
	
		int color = board[row][col];	
		
		for(int i = row; i < row + size; i++) {
			for(int j = col; j < col + size; j++) {
				if(board[i][j] != color) {
					return false;
				}
			}
		}
		return true;
	}
}

그리고 μ•„λž˜λŠ” python으둜 λ‹€μ‹œ ν‘Ό μ½”λ“œμž…λ‹ˆλ‹€!

N = int(input())
paper = []
result = [0, 0]
def solution(x,y,n):
    color = paper[x][y]
    for i in range(x, x+n):
        for j in range(y, y+n):
            if color != paper[i][j]:
                solution(x,y,n//2)
                solution(x, y+n//2, n//2)
                solution(x+n//2,y,n//2)
                solution(x+n//2,y+n//2,n//2)
                return 0
    if color == 0:
        result[0] += 1
    else :
        result[1] += 1

for i in range(N):
    paper.append(list(map(int, input().split())))

solution(0,0,N)
print(result[0])
print(result[1])

if (checkPaper(x = x, y = y, n = n, paper = paper, target = 1) { blue++ }) return
if (checkPaper(x = x, y = y, n = n, paper = paper, target = 0) { white++ }) return

val divN = n / 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄λ ‡κ²Œ n//2뢀뢄을 κ·Έλƒ₯ 보기 νŽΈν•˜κ²Œ λ§Œλ“€ 수 μžˆλ„€μš”!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ³€μˆ˜λ₯Ό λ”°λ‘œ μ €μž₯ν•˜μ§€ μ•Šμ•„λ„ μ»΄νŒŒμΌλŸ¬κ°€ μ΅œμ ν™”ν•΄μ„œ μ—¬λŸ¬λ²ˆ 연산이 μΌμ–΄λ‚˜μ§„ μ•Šκ² μ§€λ§Œ..개인적으둜 λ‹€λ₯Έ μ‚¬λžŒμ΄ μ΄ν•΄ν•˜κΈ° 쉽도둝 이름 μ§€μ–΄μ£ΌλŠ” νŽΈμž…λ‹ˆλ‹Ή!

Copy link
Collaborator

@wkdghdwns199 wkdghdwns199 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

white_color = 0 
blue_color = 0

def divide(start_x, end_x, start_y, end_y) :
    global white_color, blue_color
    checking_color = paper[start_x][start_y]
    sw=0
    for index_x in range(start_x, end_x):
        for index_y in range(start_y, end_y):
            if paper[index_x][index_y] != checking_color :
                sw=1
                break
        if sw==1 : break
    
    if sw==0 : 
        if checking_color == 1 :
            blue_color = blue_color +1
        else :
            white_color = white_color + 1
    else :
        divide(start_x, int((start_x + end_x)/2), start_y, int((start_y+end_y)/2))
        divide(start_x, int((start_x+end_x)/2), int((start_y+end_y)/2), end_y)
        divide(int((start_x+end_x)/2), end_x, start_y, int((start_y+ end_y)/2))
        divide(int((start_x+end_x)/2), end_x, int((start_y+end_y)/2), end_y)
    return 

        
import sys
input = sys.stdin.readline



N = int(input())
paper = [list(map(int, input().split())) for _ in range(N)]
 
divide(0,N,0,N)


print(white_color)
print(blue_color)

@alstjr7437 alstjr7437 removed the request for review from fnzksxl March 4, 2024 03:53
@SeongHoonC SeongHoonC merged commit 77bb6b1 into main Mar 5, 2024
5 checks passed
@SeongHoonC SeongHoonC deleted the 12-SeongHoonC branch March 5, 2024 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants