洛谷题单3-P4956 [COCI 2017 2018 #6] Davor-python-流程图重构

题目描述

在征服南极之后,Davor 开始了一项新的挑战。下一步是在西伯利亚、格林兰、挪威的北极圈远征。

他将在 2018 年 12 月 31 日开始出发,在这之前需要一共筹集 n 元钱。

他打算在每个星期一筹集 x 元,星期二筹集 x +k 元,......,星期日筹集 x +6k 元,并连续筹集 52 个星期。其中 x ,k 为正整数,并且满足 1≤x≤100。

现在请你帮忙计算 x ,k 为多少时,能刚好筹集 n 元。

如果有多个答案,输出 x 尽可能大,k 尽可能小的。注意 k 必须大于 0。

输入格式

The first line of input contains the integer N (1456 ≤ N ≤ 145600), the number from the task.

输出格式

The first line of output must contain the value of X (0 < X ≤ 100 ), and the second the value of

K (K > 0 ).

输入输出样例

输入

复制代码
1456

输出

复制代码
1
1

方式-解方程

代码

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

    @staticmethod
    def oi_test():
        """提供测试数据"""
        return 1456

    @staticmethod
    def solution(num):
        '''
          平均一天 为x + 3k
          k为自变量 x为因变量
          由k 返回去找 x
          由于只需要找x最大的,所以 k由小到大
        '''
        for k in range(1, num):
            if num / 364 - 3 * k <= 100:  # k为自变量 x为因变量
                x = num / 364 - 3 * k
                print(int(x))
                print(k)
                break


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

if __name__ == '__main__':
    num = oi_test()
    # num = oi_input()
    solution(num)

流程图

是 满足 不满足 否 开始 输入num 初始化k=1 k < num? 计算条件: num/364 -3k ≤100 计算x = num/364 -3k 输出int(x)和k 结束 k += 1

相关推荐
复杂网络15 分钟前
论最小 Agent 计算机的形态
算法
曲幽25 分钟前
刚部署的 LibreTranslate 频频翻车?我掏出了 20 年前的 StarDict 词典,用 FastAPI 搭了个本地词典翻译 API
python·fastapi·web·translate·goldendict·libretranslate·stardict·pystardict
荣码43 分钟前
用Streamlit给AI应用套个界面,10行代码出Web页面
java·python
兵慌码乱10 小时前
基于Python+PyQt5+SQLite的药房管理系统实现:事务一致性与界面解耦全流程解析
python·sqlite·信号与槽·pyqt5·数据库设计·桌面应用开发·事务处理
金銀銅鐵12 小时前
[Python] 体验用欧几里得算法计算最大公约数的过程
python·数学
FreakStudio16 小时前
W55MH32L-EVB 上手测评:硬件 TCP/IP 加持的以太网单片机,MicroPython 零门槛开发
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy·电子计算机
kisshyshy16 小时前
🍦 雪糕、食堂、火车厢:三幅漫画吃透栈、队列与链表
javascript·算法
用户03321266636717 小时前
使用 Python 从零创建 Word 文档
python
Csvn21 小时前
Python 两大经典坑点 —— 可变默认参数 & 闭包延迟绑定
后端·python
曲幽1 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate