Instantly share code, notes, and snippets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
for(int i = 1; i <= 2025; i++) { | |
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { | |
System.out.println("год весокосный " + i); | |
} else { | |
System.out.println("год не весокосный " + i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
switch нельзя использовать с числами с плавающей точкой(float), Нельзя использовать long, double и boolean | |
else if = elif(в питоне) | |
#1 | |
Пример: Дни недели | |
С if-else: | |
int day = 3; | |
String dayName; | |
if (day == 1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or | |
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter. | |
public class Main { | |
public static void main(String[] args) { | |
int mana = 120; | |
System.out.println(mana); | |
mana += 20; | |
System.out.println(mana); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args){ | |
// OUTPUT | |
System.out.println("hello world"); | |
int life = 42; | |
System.out.println(life); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
def bag(weights, values, W): | |
n = len(values) | |
dp = [[0]*(W+1) for _ in range(n+1)] | |
for i in range(1, n+1): | |
for w in range(1, W+1): | |
if weights[i-1] <= w: | |
dp[i][w] = max(dp[i-1][w], dp[i-1][w-weights[i-1]] + values[i-1]) | |
else: | |
dp[i][w] = dp[i-1][w] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Рекурсивынй алгоритм | |
1. Обход графов в глубину | |
2. Обход графов в ширину | |
75, 77 тренировки по графам | |
n = int(input()) | |
s = input() | |
matrix = [] | |
for _ in range(n): | |
matrix.append(list(map(int, ('0 '*n).split()))) | |
s = input() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1вариант | |
хранить 2 множества | |
2 вариант | |
хранить матрицу смежности | |
n = int(input()) | |
s = input() | |
edges = [] | |
while s != "0": | |
edges.append(list(map(int, s.split()))) | |
s = input() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
a = int(input("")) | |
b = list(input("")) | |
for i in range(-1, 1, -len(b)-1): | |
if b[i] == "<": | |
b.pop(i) | |
print(b) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
#1 | |
K = int(input()) | |
P = int(input()) | |
S = int(input()) | |
a = S // (K * (1 + P / 100)) | |
print(round(a)) | |
#2 | |
x1 = int(input("x коорд угла плота юго запад ->")) | |
y1 = int(input("y коорд угла плота юго запад ->")) | |
x2 = int(input("x коорд угла плота Северо восток ->")) |
Joskipank /gist:ed6ced08987af4790ec26b00650d5776
Last activeMarch 16, 2025 14:48
Задачи с бинарным поиском This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
#Коровы и стойл | |
def check(x): | |
pelm = 1 | |
last_pelm = coords[0] | |
for i in coords: | |
if i - last_pelm >= x: | |
pelm+= 1 | |
last_pelm = i | |
return pelm >= k | |
coords = [0, 3, 4, 5, 7, 12, 36, 55, 102] |
NewerOlder