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

相关推荐
踏着七彩祥云的小丑4 小时前
pytest——Mark标记
开发语言·python·pytest
Dream of maid4 小时前
Python12(网络编程)
开发语言·网络·php
W23035765735 小时前
经典算法:最长上升子序列(LIS)深度解析 C++ 实现
开发语言·c++·算法
Y4090015 小时前
【多线程】线程安全(1)
java·开发语言·jvm
不爱吃炸鸡柳5 小时前
Python入门第一课:零基础认识Python + 环境搭建 + 基础语法精讲
开发语言·python
minji...6 小时前
Linux 线程同步与互斥(三) 生产者消费者模型,基于阻塞队列的生产者消费者模型的代码实现
linux·运维·服务器·开发语言·网络·c++·算法
Dxy12393102166 小时前
Python基于BERT的上下文纠错详解
开发语言·python·bert
语戚7 小时前
力扣 968. 监控二叉树 —— 贪心 & 树形 DP 双解法递归 + 非递归全解(Java 实现)
java·算法·leetcode·贪心算法·动态规划·力扣·