zoukankan      html  css  js  c++  java
  • [Swift]LeetCode1237. 找出给定方程的正整数解 | Find Positive Integer Solution for a Given Equation

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(let_us_code)
    ➤博主域名:https://www.zengqiang.org
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/11712818.html
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    Given a function  f(x, y) and a value z, return all positive integer pairs x and y where f(x,y) == z.

    The function is constantly increasing, i.e.:

    f(x, y) < f(x + 1, y)
    f(x, y) < f(x, y + 1)
    The function interface is defined like this: 

    interface CustomFunction {
    public:
      // Returns positive integer f(x, y) for any given positive integer x and y.
      int f(int x, int y);
    };
    For custom testing purposes you're given an integer function_id and a target z as input, where function_id represent one function from an secret internal list, on the examples you'll know only two functions from the list.  

    You may return the solutions in any order. 

    Example 1:

    Input: function_id = 1, z = 5
    Output: [[1,4],[2,3],[3,2],[4,1]]
    Explanation: function_id = 1 means that f(x, y) = x + y
    Example 2:

    Input: function_id = 2, z = 5
    Output: [[1,5],[5,1]]
    Explanation: function_id = 2 means that f(x, y) = x * y

    Constraints:

    1 <= function_id <= 9
    1 <= z <= 100
    It's guaranteed that the solutions of f(x, y) == z will be on the range 1 <= x, y <= 1000
    It's also guaranteed that f(x, y) will fit in 32 bit signed integer if 1 <= x, y <= 1000


    给出一个函数  f(x, y) 和一个目标结果 z,请你计算方程 f(x,y) == z 所有可能的正整数 数对 x 和 y。

    给定函数是严格单调的,也就是说:

    f(x, y) < f(x + 1, y)
    f(x, y) < f(x, y + 1)
    函数接口定义如下:

    interface CustomFunction {
    public:
      // Returns positive integer f(x, y) for any given positive integer x and y.
      int f(int x, int y);
    };
    如果你想自定义测试,你可以输入整数 function_id 和一个目标结果 z 作为输入,其中 function_id 表示一个隐藏函数列表中的一个函数编号,题目只会告诉你列表中的 2 个函数。  

    你可以将满足条件的 结果数对 按任意顺序返回。

    示例 1:

    输入:function_id = 1, z = 5
    输出:[[1,4],[2,3],[3,2],[4,1]]
    解释:function_id = 1 表示 f(x, y) = x + y
    示例 2:

    输入:function_id = 2, z = 5
    输出:[[1,5],[5,1]]
    解释:function_id = 2 表示 f(x, y) = x * y

    提示:

    1 <= function_id <= 9
    1 <= z <= 100
    题目保证 f(x, y) == z 的解处于 1 <= x, y <= 1000 的范围内。
    在 1 <= x, y <= 1000 的前提下,题目保证 f(x, y) 是一个 32 位有符号整数。

  • 相关阅读:
    springAOP源码分析之篇三:代理对象的执行
    springAOP源码分析之篇二:代理对象的生成
    css样式float造成的浮动“塌陷”问题的解决办法
    css font的简写规则
    CSS学习
    工具
    用过的库
    The requested URL ***** was not found on this serve
    修改DeDe标签Pagelist分页样式
    DedeCms autoindex和itemindex使用介绍
  • 原文地址:https://www.cnblogs.com/strengthen/p/11712818.html
Copyright © 2011-2022 走看看