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

相关推荐
COOCC13 分钟前
激活函数全解析:定义、分类与 17 种常用函数详解
人工智能·深度学习·神经网络·算法·机器学习·计算机视觉·自然语言处理
林下清风~13 分钟前
力扣hot100——347.前K个高频元素(cpp手撕堆)
算法·leetcode·职场和发展
沃洛德.辛肯30 分钟前
PyTorch 的 F.scaled_dot_product_attention 返回Nan
人工智能·pytorch·python
noravinsc42 分钟前
人大金仓数据库 与django结合
数据库·python·django
郭尘帅66643 分钟前
Vue3中实现轮播图
开发语言·前端·javascript
豌豆花下猫1 小时前
Python 潮流周刊#102:微软裁员 Faster CPython 团队(摘要)
后端·python·ai
进击的小白菜1 小时前
Java回溯算法解决非递减子序列问题(LeetCode 491)的深度解析
java·算法·leetcode
Thomas_YXQ1 小时前
Unity3D Overdraw性能优化详解
开发语言·人工智能·性能优化·unity3d
lanbing1 小时前
PHP 与 面向对象编程(OOP)
开发语言·php·面向对象
yzx9910131 小时前
Gensim 是一个专为 Python 设计的开源库
开发语言·python·开源