/
Programmi21
/
demo_integration
Обзор
Документация
Войти
/
Programmi21
/
demo_integration
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
task1_cruise.py
138 строк
5 KB
Programmi21
create: .cm-token, app.py, docker-compose.yml, Dockerfile, instruction.md, README.md, requirements.txt, task1_cruise.py, task2_visibility.py, task3_constellation.py
10 апр 2026, 16:36
Верифицирован
10 апр 2026, 16:36
01ec612
Код
Авторство
О чём код?
import math from collections import defaultdict def solve_robinson_cruise(data): mass_shuttle = data["mass_shuttle"] mass_fuel_unit = data["mass_fuel_unit"] power_per_unit = data["power_per_unit"] oxygen_time = data["oxygen_time"] total_fuel = data["total_fuel"] fuel_consumption = data["fuel_consumption"] bodies_list = data["bodies"] edges = data["edges"] bodies = {b["id"]: b for b in bodies_list} body_ids = set(bodies.keys()) all_nodes = set() for edge in edges: all_nodes.add(edge["from"]) all_nodes.add(edge["to"]) start_point = None rescue_point = None for node in all_nodes: if node not in body_ids: if start_point is None: start_point = node else: rescue_point = node if start_point is None or rescue_point is None: return {"can_reach": False} graph = defaultdict(list) for edge in edges: graph[edge["from"]].append((edge["to"], edge["distance"])) graph[edge["to"]].append((edge["from"], edge["distance"])) def find_all_paths(start, end, max_depth=10): all_paths = [] stack = [(start, [start])] while stack: node, path = stack.pop() if len(path) > max_depth: continue if node == end: all_paths.append(path) continue for neighbor, _ in graph[node]: if neighbor not in path: stack.append((neighbor, path + [neighbor])) return all_paths all_paths = find_all_paths(start_point, rescue_point) if not all_paths: return {"can_reach": False} def calculate_flight_time(route): fuel = total_fuel fuel -= fuel // fuel_consumption if fuel <= 0: return float('inf') total_distance = 0 for i in range(len(route) - 1): for neighbor, dist in graph[route[i]]: if neighbor == route[i+1]: total_distance += dist break current_mass = mass_shuttle + fuel * mass_fuel_unit velocity = 0 distance_traveled = 0 time_spent = 0 fuel_for_acceleration = fuel // 2 fuel_remaining = fuel - fuel_for_acceleration for _ in range(fuel_for_acceleration): if fuel_for_acceleration == 0: break acceleration = power_per_unit / current_mass velocity += acceleration distance_traveled += velocity time_spent += 1 current_mass -= mass_fuel_unit if distance_traveled > total_distance / 2: break for i in range(1, len(route) - 1): body_id = route[i] if body_id in bodies and bodies[body_id]["gravity_assists"]: assists = bodies[body_id]["gravity_assists"] best = max(assists, key=lambda a: a["velocity_gain"] / a["time_to_execute"]) velocity += best["velocity_gain"] fuel_remaining -= best["fuel_consumption"] time_spent += best["time_to_execute"] if fuel_remaining < 0: return float('inf') current_mass -= best["fuel_consumption"] * mass_fuel_unit remaining_distance = total_distance - distance_traveled if velocity > 0: coast_time = remaining_distance / velocity time_spent += coast_time else: return float('inf') for _ in range(fuel_remaining): if velocity <= 0: break deceleration = power_per_unit / current_mass velocity = max(0, velocity - deceleration) time_spent += 1 current_mass -= mass_fuel_unit if time_spent > oxygen_time: return float('inf') return time_spent best_time = float('inf') best_route = None for path in all_paths: flight_time = calculate_flight_time(path) if flight_time < best_time: best_time = flight_time best_route = path if best_route is None or best_time == float('inf'): return {"can_reach": False} return { "can_reach": True, "min_flight_time": round(best_time, 1), "route": best_route }