728x90

어이없어서 올림. 

pypy3으론 잘돌아감.

python3 쓰면 시간초과남. 

 

from collections import Counter

N=int(input())
list=[]
ave=0
for i in range(N):
  list.append(int(input()))

list.sort()

for i in range(N):
  ave+=list[i]

print(round(ave/N))
mid=int((N-1)/2)
print(list[mid])

cnt_li = Counter(list).most_common()
if len(cnt_li) > 1 and cnt_li[0][1]==cnt_li[1][1]: #최빈값 2개 이상
    print(cnt_li[1][0])
else:
    print(cnt_li[0][0])


dif=max(list)-min(list)
print(dif)

 

시간초과 해결하려면 

 

input() 대신에 sys import 한다음에 int(sys.stdin.readline())쓰면 됨 

728x90
728x90

N = input()
list = []
M=[]
check=0
for x in range(int(N)):
  inp=int(input())
  list.append(inp)

for x in range(2,int(min(list))+1):
  for y in range(int(N)):
    ms=list[y]%(x)
    M.append(ms)
    a=M[0]
    b=M[y]
    if(a!=b):
      check=1
      break
      
  if(check!=1):
    print(x)

  M=[]
  check=0

 

(일단은 돌아가는 코든데 쓴게 아까워서 올리는 오답)

 

이건 오답이다. 

사실 이거 돌려봐도 답은 제대로 나온다. 

근데 왜 오답이냐고?

 

만약 이게 정답이였다면 문제가 골드일 리가 없겠지. 

시간초과가 뜬다. 

 

이유는 다음과 같다:

N이 1,000,000,000 보다 작거나 같은 수 이기에 일일히 나머지를 찾는 방식을 쓰면 컴퓨터가 좆된다ㅋㅋㅋㅋㅋㅋ

문제를 제대로 안읽은걸 반성하자. 

시발.

 


그래서 쓴 방법은 수학을 사용하는것이다. 

한국수학 수학 상에 나오는 내용을 그대로 사용해서 연립방정식을 풀면 답이 나온다 (이건 내 과외 말버릇)

마침 내 학생중 하나가 수학 상을 하니 이걸 숙제로 내줄까도 생각중임 

 

이렇게 연립방정식을 만들어서 나머지 R을 없애주고 M에 대한 식을 만듧

 

import math
N = int(input())
s = []
M = []
gcd = 0 #greatest commend divisor (최대공약수)
for i in range(N):
    s.append(int(input()))
    if i == 1:
        gcd = abs(s[1] - s[0])
    gcd = math.gcd(abs(s[i] - s[i - 1]), gcd)
gcd_last = int(gcd ** 0.5) #너무 많이 돌리면 시간초과뜸
for i in range(2, gcd_last + 1):
    if gcd % i == 0: #최대공약수가 어떤 수로 나눠졌을때 나머지가 0이 되면 그 어떤 수는 최대공약수의 약수가 된다 (즉 약수찾는 반복문임)
        M.append(i) 
        M.append(gcd // i) #최대공약수를 반갈죽해서 넣어주는거랑 동시에 하면 연산이 줄어듦 (gcd ** 0.5 최대공약수의 루트만큼만 계산하기 때문) 시간초과 방지
M.append(gcd) #당연히 최대공약수도 넣어줘야지
M = list(set(M)) #중복제거
M.sort() #정리함
for i in M:
    print(i, end = ' ')

 

자세한 설명은 생략한다. (위에 이미 다 주석으로 설명되있음)

728x90

'언어는 과-학인가요? > python 파이썬' 카테고리의 다른 글

백준 1072 파이썬 - 게임  (0) 2022.07.27
백준 골드 (2447번) 파이썬 - 별찍기  (0) 2022.07.27
백준 골드 (2493번) 파이썬  (0) 2022.07.27
백준 2108  (0) 2022.07.26
백준 1단계 문제풀이  (0) 2022.07.04
728x90

2557

print('Hello World!')

 

10718

print('강한친구 대한육군\n강한친구 대한육군')

 

10171

print('\\    /\\\n )  ( \')\n(  /  )\n \\(__)|')

역슬래쉬 (\) 와 따음표 (",') 앞에는 \를 붙여줍니다.

 

10172

print('|\\_/|\n|q p|   /}\n( 0 )\"\"\"\\\n|\"^\"`    |\n||_/=\\\\__|')

10171과 동일

 

1000

A,B=input().split()
print(int(A)+int(B))

.split()으로 A 와 B에 input 값을 나누어 넣는다

A와 B를 int형으로 바꿔 프린트한다

 

1001

A,B=input().split()
print(int(A)-int(B))

1000번과 동일 

int 형으로 바꾼 두 input값 사이에 부호만 바꿈.

 

10998

A,B=input().split()
print(int(A)*int(B))

1000번과 동일

 

1008

A,B=input().split()
print(int(A)/int(B))

1000번과 동일

 

10869

A,B=input().split()
print(int(A)+int(B))
print(int(A)-int(B))
print(int(A)*int(B))
print(int(int(A)/int(B)))
print(int(A)%int(B))

나누기 할때는 나누면 정수로 안나오는 경우도 있기에 int를 다시한번 더 붙여주는

 

10926

A=input()
print(A+'??!')

input형태를 안알려줘도 알아서 되는 갓이썬

 

18108

A=input()
print(int(A)-543)

꼭 형태를 int로 바꿔줍시다

 

10430

A,B,C=input().split()
A=int(A)
B=int(B)
C=int(C)
print((A+B)%C)
print(((A%C) + (B%C))%C)
print((A*B)%C)
print(((A%C)*(B%C))%C)

A, B, C를 인트로~

 

2588

A = int(input())
B = input()
for i in range(3, 0, -1) :
    print(A * int(B[i - 1]))
print(A * int(B))

A 는 정수니까 int형으로 받고, B는 그냥 문자열로 저장해 준다. 

문자열 (배열)은 이제 for반복문 안에 들어가서 2번째 배열부터 0번째 배열까지 순서대로 뽑힌다

그리고 마지막에 그냥 AB값 곱해준거 하면 끝

 

25083

print('         ,r\'\"7\nr`-_   ,\'  ,/\n \\. \". L_r\'\n   `~\\/\n      |\n      |')

10171과 동일

728x90
728x90

네 인턴십때 열심히 썼던 '내인생 첫 유용한 언어'

(다시 생각해보니 유니티 할때 쓴 C#이 처음이긴 하지만)

 

2년쯤 지나니 뇌가 리셋됐군요.

 

초심부터 잡고 올라가겠습니다.

728x90
728x90

미적분 가르치는건 세상에서 제일 즐거운 일이다. 이제 미분 끝나고 곧 적분하는데 너무 설렌다

728x90
728x90

이 된느낌 초등과외는 개빡세게 1학년부터 6학년까지 다 받아보면서 마스터했다면 

지금은 입소문타서 중등과외만 계속 들어오고있음

미적분 가르치고싶다1!!!!!! 고등학생 과외 안들어오냐아

지금 고2 미적분 한명 하는데 ㄹㅇ 걔가 제일 재밌어 미적분 사랑해

진짜 열정적으로 가르칠수 있음 미적분이면 

빨리 구분구적법 가르치고싶다 하응ㅇ일랑어ㅣㄹ갈

2023년 목표는 고등과외 전문이다 딱기다려라

지금 가르치는 중3들 다 고딩으로 만들어서 미적분 가르쳐버릴거야(?) 

미적분 개념만 전문적으로 올리는 유튜브 계정을 만들어볼까

728x90
728x90

Client-server architecture

  • World Wide Web (WWW) uses the client-server architecture
    • Clients obtain service from a centralized server
    • Server waits for client requests and make response

The OSI network model

  • communication between clients and servers can be seen in multiple layers
    • Abstraction è reducing complexity of problems to smaller ones
    • Division of labour

THE OSI NETWORK MODEL

 

Communication protocols

  • Clear definition of steps is needed for two computers to communicate
    • rules
    • syntax
    • semantics
    • synchronization of communication
    • error recovery methods
  • There are protocols for every layer in the networking model
  • The internet engineering Task force (IETF) develops and promotes voluntary internet standards

MAC and IP addresses

  • Mac address (layer2): locating a piece of communication device on a local network
  • IP address(layer3): identifying a network interface in networks
    • IPv4 (32-bit) vs IPv6 (128-bit)
    • Public addresses vs private addresses
      • Private addresses limit datagrams to be sent within local network only
      • e.g., 192.168.1.123 is only meaningful within a local network
  • The ARP table on a device maintains the correspondence between MAC addresses and IP addresses within a local network

TCP VS UDP

  • Layer 4 protocols: ensuring reliability of data transmission
  • Transmission control protocols (TCP)
    • Handshakes to establish a connection
    • Built in system to check for errors
    • Guarantee for data order and completeness
    • Good for HTTPSs, HTTP etc. 
  • User Datagram Protocols (UDP_
    • connectionless -> reducing the overhead of computation (time)
    • Extensive error checking and recovery not required
    • Good for: video conferencing, media streaming etc

Communicating over ports 

  • In networking, connections are made on ports of a network device
  • Each port is "listen to" served by one piece of software server
  • Well known ports: 0-1023 (Http:80, Https:443)
  • Registered ports: 1024-49151
  • Private ports:49152-65535

Socket

  • In network programming, a network socket is an endpoint for communication
  • socket=transport protocol+IP address+port number
  • Implementation depends on the programming language/environment

Localhost

  • It is also possible to have both ends of communication only on one computer
    • Although it is in the same computer, this way allows communication to still go through network layers in the OS
  • Usually identified in the computer as "localhost" or 127.0.0.1

Hypertext transfer protocol

  • HTTP - hypertext transfer protocol
  • Communication is initiated by a client 
    • a client sends a HTTP request to a server
    • the server returns a HTTP response to the client 
  • It is stateless
    • every request is treated as an independent request
    • the protocol itself does not offer any means to relate two separate request
  • HTTP/1.1 — 1997, HTTP/2 — 2015, HTTP/3 — expired draft (2020)

 

HTTP clients 

  • Web client (“user-agent”): a software communicating with the web server over HTTP or HTTPS
    • web browsers: for end-user experience
      • html/css rendering
      • js execution
      • web technologies
    • web crawlers/ search engines
    • programmatic interfaces

HTTP servers

  • Web server: handling requests for web documents with http/https, supporting server-side scripts
    • apache (was still the first last yr!)
    • nginx
    • Microsoft ISS
    • node.js
  • Web caching
    • forward/reverse proxies
    • Content delivery networks(CDN)

 

728x90

'언어는 과-학인가요? > 전반적인 web development (html css JS )' 카테고리의 다른 글

HTML 에 CSS파일 연결하는법  (0) 2022.11.15
HTML Article 과 Section의 차이  (0) 2022.11.15
Web security  (0) 2022.03.03
CSS로 form 만들기  (0) 2022.01.19
유용한 CSS들  (0) 2022.01.14
728x90

Handle user passwords

  • Password should never be stored in plain text
    • hashing: a one-way function transforms the password into hashed text which is good enough for validation without storing the actual password

HTTP authentication

1. If needed, server can send response with hander www-authenticate(provides scheme to use) with a challenge

2. 

 

HTTP authorization schemes 

  • In the authorization request header, different schemes are allowed 

 

 

Json web tokens(JWT)

  • JWT gets popularity as a way yo generate authentication tokens
  • JWT always has 3 parts with a dot in between
    • header(algorithm and token type)
    • payload(the actual contents)
    • signature(the header+payload encoded, signed with server's private key)
  • The 3 parts are encoded separately in based 64

 

JWT VS. session

  • data stored in JWT and session cannot be tempered with at the client side 
  • with JWT token, data are kept on client side whereas 

 

Cross-site threats

  • cross-site scripting(xss)
    • stored XSS 
    • reflected XSS
    • DOM based XSS
  • Cross-site request forgery(CSRF)
    • if request origin of an action is not checked, a request could be made on a malicious site other than the expected site 
728x90

+ Recent posts