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

相关推荐
TomEval6 小时前
【测AI】第26篇:线上模型监控与告警体系 — 测试不是终点
人工智能·python·功能测试·ai
prince_zxill7 小时前
PEP 751 pylock.toml 实测:pip 26.3 装 6 个包版本全钉死,但 [web] 选不中任何东西
python·pip·依赖管理·pep 751
ShineWinsu8 小时前
对于Qt:QFormLayout常见属性以及方法的解析
开发语言·c++·qt·面试·客户端·表单·qformlayout
Thanks_ks8 小时前
Python 的垃圾回收——引用计数撑起日常,分代回收收拾残局
python·内存管理·垃圾回收·循环引用·引用计数·gc 模块·weakref
CyrusYiVPP8 小时前
实测 uv 0.13.7:同一套包,pip 装 94 秒,它只用 19 秒
人工智能·python
罗西的思考9 小时前
【轻量化复刻大模型 / KIMI K3】Muon 优化器及 训练系统
人工智能·算法·机器学习
yiangL_9 小时前
Python 学习笔记:递归、turtle绘图、字符串与函数
笔记·python·学习
ashiho10 小时前
【LeetCode hot 100】3. 无重复字符的最长子串 (三种解法)
java·数据结构·后端·算法·leetcode·滑动窗口
数据工匠老o10 小时前
数据库没死,业务卡住了:行锁等待、元数据锁、长事务的排查路径
数据库·算法·架构
lula88810 小时前
PVC-U、PVC-C、PVC-O 差一个字母,差的是三种增强路线
python