20251113 baekjoon
This commit is contained in:
parent
cc54ff86f3
commit
a8e072c3b2
22
code_study/Baekjoon/python/17103.py
Normal file
22
code_study/Baekjoon/python/17103.py
Normal file
@ -0,0 +1,22 @@
|
||||
import sys
|
||||
input = sys.stdin.readline
|
||||
|
||||
nums = [int(input()) for _ in range(int(input()))]
|
||||
num_max = max(nums)
|
||||
|
||||
isPrime = [True for _ in range(num_max+1)]
|
||||
isPrime[0], isPrime[1] = False, False
|
||||
for i in range(2,int(num_max**0.5)+1) :
|
||||
if isPrime[i] :
|
||||
for j in range(i*i, num_max+1, i) :
|
||||
isPrime[j] = False
|
||||
|
||||
result = []
|
||||
for n in nums :
|
||||
count = 0
|
||||
for i in range(2,n//2 + 1) :
|
||||
if isPrime[n-i] and isPrime[i] :
|
||||
count += 1
|
||||
result.append(str(count))
|
||||
|
||||
print('\n'.join(result))
|
||||
37
code_study/Baekjoon/ts/17404.ts
Normal file
37
code_study/Baekjoon/ts/17404.ts
Normal file
@ -0,0 +1,37 @@
|
||||
export {};
|
||||
const input = require("fs").readFileSync(0).toString().trim().split("\n");
|
||||
const N = Number(input[0]);
|
||||
|
||||
let R: number[] = [];
|
||||
let G: number[] = [];
|
||||
let B: number[] = [];
|
||||
|
||||
input.slice(1).forEach(line => {
|
||||
const [r,g,b]: number[] = line.split(" ").map(Number);
|
||||
R.push(r);
|
||||
G.push(g);
|
||||
B.push(b);
|
||||
});
|
||||
|
||||
const min = (a: number,b: number): number => Math.min(a,b);
|
||||
let result: number[] = [];
|
||||
|
||||
for(let i=0; i<3; i++) {
|
||||
let prevR = i!=0 ? 1000 : R[0];
|
||||
let prevG = i!=1 ? 1000 : G[0];
|
||||
let prevB = i!=2 ? 1000 : B[0];
|
||||
|
||||
for(let i=1; i<N; i++) {
|
||||
const curR = R[i] + min(prevG, prevB);
|
||||
const curG = G[i] + min(prevR, prevB);
|
||||
const curB = B[i] + min(prevG, prevR);
|
||||
|
||||
[prevR, prevG, prevB] = [curR, curG, curB];
|
||||
}
|
||||
|
||||
if(i===0) result.push(min(prevG, prevB));
|
||||
else if(i===1) result.push(min(prevR, prevB));
|
||||
else result.push(min(prevG, prevR));
|
||||
}
|
||||
|
||||
console.log(min(result[0], min(result[1], result[2])));
|
||||
Loading…
x
Reference in New Issue
Block a user