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

相关推荐
Achou.Wang14 分钟前
深入理解go语言-第5章 并发编程——Go的灵魂
大数据·算法·golang
韭菜炒鸡肝天22 分钟前
VTK开发笔记(一):VTK介绍,Qt..+VSx+VTK.编译
开发语言·笔记·qt
The Chosen One98522 分钟前
高进度算法模板速记(待完善)
java·前端·算法
Gu Gu Study26 分钟前
ScoutLoop开放域深度研究引擎(agent的初步设计想法)
人工智能·python
Aaron - Wistron1 小时前
Web API C# (Furion版)带 单元测试
开发语言·后端·c#
卷无止境1 小时前
写代码这件事,到底该讲究点什么?
后端·python
卷无止境1 小时前
循环复杂度到底在算什么,Python 代码怎么才能写得让人一看就懂
后端·python
lpfasd1231 小时前
MediaCrawler 项目深度分析
chrome·python·chrome devtools
Dxy12393102162 小时前
Python项目打包成EXE完整教程(PyInstaller实战避坑)
开发语言·python
bamb002 小时前
一个项目带你入门AI应用开发01
python