洛谷题单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) 结束

相关推荐
青 春 记 忆3 小时前
Dify Docker Compose 通用无损升级指南:从备份、双版本预演到切换与回滚
运维·人工智能·python·docker·容器
GlueNa2SiO33 小时前
03-Flask模板引擎Jinja2详解
笔记·python·flask
「QT(C++)开发工程师」4 小时前
C++ 11 常用for循环
开发语言·c++
我还记得那天4 小时前
0 初识C++
开发语言·c++
FfHUCisI4 小时前
Go 编译过程全景
开发语言·后端·golang
FfHUCisI4 小时前
Golang 语法分析与 AST:Parser 与 go/ast
开发语言·后端·golang
Asize5 小时前
146. LRU 缓存
算法
Asize5 小时前
543. 二叉树的直径
算法
lemon_sjdk5 小时前
ObjectProperty
java·开发语言·算法