알고리즘/Codeforces

Codeforces Round #532 (Div. 2) A ~ C

70825 2021. 1. 8. 18:11
반응형

codeforces.com/contest/1100

 

Dashboard - Codeforces Round #532 (Div. 2) - Codeforces

 

codeforces.com

 

풀은 문제: A, B, C
못 풀은 문제: D, E, F

 

난이도

A - 1000

B - 1300

C - 1200

D - 2500

E - 2200

F - 2500

 

 

B번 생각하는데 오래 걸려서 아쉬웠음

 

 

 

Python Fast I/O

 

import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading

def main():
    return

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    """sys.setrecursionlimit(400000)
    threading.stack_size(40960000)
    thread = threading.Thread(target=main)
    thread.start()"""
    main()

 

 

 

 

 

 

A. Roman and Browser

 

이 문제는 k보다 작은 수만큼 for문을 돌리고, 또 n만큼 for문을 돌려서 i % k == j % k 를 제외한 모든 수를 리스트에 넣어준다.

그다음 리스트를 for문으로 돌려서 -1과 1의 갯수를 각각 x, y에 저장하고 abs(x-y)가 가장 큰 값을 출력하면 된다.

 

def main():
    n, k = map(int,input().split())
    D = [*map(int,input().split())]
    ans = 0
    for i in range(k):
        A = []
        for j in range(n):
            if j % k == i % k: continue
            A.append(D[j])
        x, y = 0, 0
        for j in range(len(A)):
            if A[j]==1:x+=1
            else:y+=1
        ans = max(ans, abs(x-y))
    print(ans)

 

 

 

 

B. Build a Contest

난이도 1~n까지 전부 모아야 대회를 개최할 수 있을 떄, 대회를 총 몇번 할 수 있는지 구하는 문제이다.

일단 이건 O(m)으로 풀 수 있고, 난이도 n의 문제가 현재 몇 개 만들어졌는지 구하는 problem 리스트와 총 대회를 몇번 개최할 수 있는지 ans리스트를 만들어준다.

ans리스트의 한 원소엔 모든 문제의 난이도가 1개씩 들어갈 수 있는 분량이 들어가있다.

이게 무슨 소리냐면 n=3이고, 1, 1, 1, 2, 3, 3의 문제가 있다면 for문을 돌릴 때, problem[1] = 1, ans[problem[1]] = ans[1] = 1 이고 problem[1] = 2, ans[problem[1]] = ans[2] = 1 => problem[1] = 3, ans[problem[1]] = ans[3] = 1 이렇게 어떤 난이도에 문제가 여러개가 있으면 ans에 하나씩 넣어준다. 이어서하면 problem[2] = 1, ans[problem[2]] = ans[1] = 2 이고, problem[3] = 1, ans[problem[3]] = ans[1] = 3이다. 이때 처음 개최할 라운드에 모든 난이도의 문제가 모였으므로 0대신 1을 출력한다. 이어서 problem[3] = 2, ans[problem[3]] = ans[2] = 2가 된다.

 

def main():
    n, m = map(int, input().split())
    a = [*map(int, input().split())]
    problem = [-1] * n
    ans = [0] * m
    for i in range(m):
        problem[a[i]-1]+=1
        ans[problem[a[i]-1]]+=1
        if ans[problem[a[i]-1]] == n:print(1,end='')
        else:print(0,end='')

 

 

 

 

 

C. NN and the Optical Illusion

 

각도에 왜 1/2를 붙이냐면 원이 n개 있을 때, 원 한 개가 차지하는 각도는 2pi / n인데, 저 각도의 반절만 사용하여 값을 구하기 때문에 pi/n이다.

 

from math import *

def main():
    n, r = map(int,input().split())
    radian = radians(360 / (2 * n))
    print(r * sin(radian) / (1-sin(radian)) )
반응형