洛谷题单2-P1424 小鱼的航程(改进版)-python-流程图重构

题目描述

有一只小鱼,它平日每天游泳 250 250 250 公里,周末休息(实行双休日),假设从周 x x x 开始算起,过了 n n n 天以后,小鱼一共累计游泳了多少公里呢?

输入格式

输入两个正整数 x , n x,n x,n,表示从周 x x x 算起,经过 n n n 天。

输出格式

输出一个整数,表示小鱼累计游泳了多少公里。

输入输出样例

输入

复制代码
3 10

输出

复制代码
2000

说明/提示

数据保证, 1 ≤ x ≤ 7 1\le x \le 7 1≤x≤7, 1 ≤ n ≤ 1 0 6 1 \le n\le 10^6 1≤n≤106。

方式

代码

python 复制代码
class Solution:
    @staticmethod
    def oi_input():
        """从标准输入读取数据"""
        x, n = map(int, input().split())
        return x, n

    @staticmethod
    def oi_test():
        """提供测试数据"""
        return 3, 10

    @staticmethod
    def solution(x, n):
        now = x - 1
        total = (n // 7) * 1250

        for _ in range(n % 7):
            if now <= 4:  # 工作日(周一到周五)
                total += 250
            now = (now + 1) % 7  # 更新到下一天

        print(total)


oi_input = Solution.oi_input
oi_test = Solution.oi_test
solution = Solution.solution

if __name__ == '__main__':
    x, n = oi_test()
    # x, n = oi_input()
    solution(x, n)

流程图

每日处理 是 否 当前是工作日?
now <= 4 循环处理剩余天数
for _ in range(remain_days) 累加工资250元
total += 250 跳过 更新星期索引
now = (now+1)%7 开始 主函数调用 读取输入数据
x, n = map(int, input().split()) 初始化当前星期索引
now = x-1 计算完整周工资
total = (n//7)*1250 计算剩余天数
remain_days = n % 7 格式化输出总工资
print(total) 结束

相关推荐
Irene19911 小时前
Python 卸载与安装(以卸载3.13.3,装3.13.13为例)
python
予早1 小时前
使用 pyrasite-ng 和 guppy3 做内存分析
python·内存分析
孤飞5 小时前
zero2Agent:面向大厂面试的 Agent 工程教程,从概念到生产的完整学习路线
算法
hef2886 小时前
如何生成特定SQL的AWR报告_@awrsqrpt.sql深度剖析单条语句性能
jvm·数据库·python
Jinkxs7 小时前
从语法纠错到项目重构:Python+Copilot 的全流程开发效率提升指南
python·重构·copilot
技术专家7 小时前
Stable Diffusion系列的详细讨论 / Detailed Discussion of the Stable Diffusion Series
人工智能·python·算法·推荐算法·1024程序员节
段一凡-华北理工大学7 小时前
【大模型+知识图谱+工业智能体技术架构】~系列文章01:快速了解与初学入门!!!
人工智能·python·架构·知识图谱·工业智能体
csdn_aspnet7 小时前
C# (QuickSort using Random Pivoting)使用随机枢轴的快速排序
数据结构·算法·c#·排序算法
IT小Qi7 小时前
iperf3网络测试工具
网络·python·测试工具·信息与通信·ip
以神为界7 小时前
Python入门实操:基础语法+爬虫入门+模块使用全指南
开发语言·网络·爬虫·python·安全·web