분류 전체보기 720

[백준][Python] 1244 스위치 켜고 끄기

XOR연산 import sys input = sys.stdin.readline N = int(input()) switches = list(map(int, input().split())) M = int(input()) for _ in range(M): a, b = map(int, input().split()) # 남학생이면 스위치 번호가 받은 수의 배수이면 그 스위치의 상태를 바꾼다. XOR(3을 받으면 3,6끔) # 여학생은 자기가 받은 스위치 번호를 중심으로 좌우가 대칭이면서 가장 많은 스위치를 포함하는 구간을 찾아 상태를 모두 바꾼다. XOR if a==1: for i in range(N): if not (i+1)%b: switches[i] ^= 1 else: size=1 while b-1-size>..

[SWEA][Python] 1220 magnetic

문제 보자마자 무지성 구현. 한칸씩 이동 이동 멈추면 반복문 종료. 다른 사람들은 0 빼고 1,2만 새 배열에 담아서 switch바꾸는 형식으로 풀었더라. 상태1에서 2를 만나면 1더하는 식으로. import sys sys.stdin = open('input.txt') def move_block(): check = 0 new_struck = 0 for i in range(N): for j in range(N): if not i == 99 and matrix[i][j] == 1: if not matrix[i+1][j]: matrix[i][j], matrix[i+1][j] = matrix[i+1][j], matrix[i][j] check = 1 elif matrix[i+1][j] == 1: matrix[i]..

[Django] admin 페이지 커스텀하기

첫번째 장고 앱 작성하기, part 7 관리자 폼 커스터마이징 수정 폼의 필드를 재정렬해 작동하는 법을 본다. admin.site.register(Question) 를 아래와 같이 수정한다. from django.contrib import admin from .models import Question class QuestionAdmin(admin.ModelAdmin): fields = ['pub_date', 'question_text'] admin.site.register(Question, QuestionAdmin) 모델의 관리자 옵션을 변경해야 할 때마다 모델 어드민 클래스를 만든 다음, admin.site.register()에 두 번째 인수로 전달한다. 수십 개의 필드가 있는 폼에 관해서는 폼을 fi..

[Django] 배경이미지 추가하기

첫번째 장고 앱 작성하기, part 6 앱의 모양과 느낌을 원하는대로 바꿔보세요 특별한 것은 정적 파일을 static 디렉토리에 모아 관리한다는 것 이외는 없다. 정적파일을 저장할 static 리렉토리 디렉토리를 지정함은 네임스페이싱을 통해 파일을 구별짓기를 원한다는 의미이다.(이름이 동일한 다른파일과) {% load static %} static 탬플릿 태그는 정적파일의 절대경로 URL을 생성한다. 배경 이미지 추가하기. images 서브 디렉토리 추가 * { padding: 0; margin: 0; box-sizing: border-box; } ul { font-family: 'Open Sans', sans-serif; font-family: 'Roboto', sans-serif; background..

[백준][Python] 21939 문제 추천 시스템

핵심은 이미 푼 문제를 각 힙에서 제거하는 매커니즘. import sys input = sys.stdin.readline from heapq import heappop,heappush from collections import defaultdict N = int(input()) min_heap = [] max_heap = [] in_list = defaultdict(bool) for _ in range(N): P, L = map(int, input().split()) heappush(min_heap,[L,P]) heappush(max_heap,[-L,-P]) in_list[P] = True M = int(input()) for _ in range(M): command = input().split() if..

[백준][Python] 22867 종점

시간정보에 대한 전처리가 귀찮은 문제. 저게 최선인가 싶긴 하다. 나머지로직은 강의실 배정, 방배정 문제와 동일. import sys input = sys.stdin.readline from heapq import heappush, heappop N = int(input()) buses = [] for _ in range(N): arrive, leave = input().split() a = int(''.join((''.join(arrive.split(':'))).split('.'))) b = int(''.join((''.join(leave.split(':'))).split('.'))) buses.append([a,b]) buses.sort() heap = [] heappush(heap,buses[0][..