当前位置: 首页 > news >正文

网站建设后台管理便捷网站手机版排名seo

网站建设后台管理便捷,网站手机版排名seo,如何发布自己做的网站,网站开发人员任职资格找出给定方程的正整数解【LC1237】 给你一个函数 f(x, y) 和一个目标结果 z,函数公式未知,请你计算方程 f(x,y) z 所有可能的正整数 数对 x 和 y。满足条件的结果数对可以按任意顺序返回。 尽管函数的具体式子未知,但它是单调递增函数&#…

找出给定方程的正整数解【LC1237】

给你一个函数 f(x, y) 和一个目标结果 z,函数公式未知,请你计算方程 f(x,y) == z 所有可能的正整数 数对 xy。满足条件的结果数对可以按任意顺序返回。

尽管函数的具体式子未知,但它是单调递增函数,也就是说:

  • f(x, y) < f(x + 1, y)
  • f(x, y) < f(x, y + 1)

函数接口定义如下:

interface CustomFunction {
public:// Returns some positive integer f(x, y) for two positive integers x and y based on a formula.int f(int x, int y);
};

你的解决方案将按如下规则进行评判:

  • 判题程序有一个由 CustomFunction9 种实现组成的列表,以及一种为特定的 z 生成所有有效数对的答案的方法。
  • 判题程序接受两个输入:function_id(决定使用哪种实现测试你的代码)以及目标结果 z
  • 判题程序将会调用你实现的 findSolution 并将你的结果与答案进行比较。
  • 如果你的结果与答案相符,那么解决方案将被视作正确答案,即 Accepted

说真的 我看了评论区才看懂题目的

暴力

  • 思路:双重循环枚举每个可能的xxxyyy,通过customfunction.f(x, y)求出运算结果,如果结果等于zzz,那么加入结果集中;由于函数是单调递增函数,因此如果结果大于zzz时,退出循环。

  • 实现

    class Solution {public List<List<Integer>> findSolution(CustomFunction customfunction, int z) {List<List<Integer>> res = new ArrayList<>();for (int i = 1; i <= 1000; i++){for (int j = 1; j <= 1000; j++){int num = customfunction.f(i, j);if (num == z){res.add(Arrays.asList(i, j));}else if (num > z){break;}}}return res;}
    }
    
    • 复杂度

      • 时间复杂度:O(C2)O(C^2)O(C2)CCC为x和y的取值范围,本题中为100010001000
      • 空间复杂度:O(1)O(1)O(1)

二分查找

  • 思路:由于函数为单调递增函数,因此可以固定xxx,二分查找yyy,二分查找的上限为1,下限为1000,假定运算结果为numnumnum

    • 如果num==znum==znum==z,那么将结果添加至结果集
    • 如果num>znum>znum>z,那么yyy向左边查询,right = mid - 1
    • 如果num==znum==znum==z,那么yyy向右边查询,left = mid + 1
  • 实现

    /** // This is the custom function interface.* // You should not implement it, or speculate about its implementation* class CustomFunction {*     // Returns f(x, y) for any given positive integers x and y.*     // Note that f(x, y) is increasing with respect to both x and y.*     // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)*     public int f(int x, int y);* };*/class Solution {public List<List<Integer>> findSolution(CustomFunction customfunction, int z) {List<List<Integer>> res = new ArrayList<>();for (int i = 1; i <= 1000; i++){int jL = 1, jR = 1000;while (jL <= jR){int mid = (jL + jR) / 2;int num = customfunction.f(i, mid);if (num == z){res.add(Arrays.asList(i, mid));break;}else if (num > z){jR = mid - 1;}else{jL = mid + 1;}}}return res;}
    }
    
    • 复杂度

      • 时间复杂度:O(ClogC)O(ClogC)O(ClogC)CCC为x和y的取值范围,本题中为100010001000
      • 空间复杂度:$O(1) $

双指针

  • 思路:当x1<x2x_1<x_2x1<x2时,如果f(x1,y1)=f(x2,y2)=zf(x_1,y_1)=f(x_2,y_2)=zf(x1,y1)=f(x2,y2)=z,那么此时y1>y2y_1>y_2y1>y2,因此可以从小到大枚举xxx,从大到小枚举yyy,那么可以固定xxx,在上次循环的yyy值作为起始值,找到本次的yyy

  • 实现

    class Solution {public List<List<Integer>> findSolution(CustomFunction customfunction, int z) {List<List<Integer>> res = new ArrayList<>();int j = 1000;for (int i = 1; i <= 1000; i++){while (j >= 1 && customfunction.f(i, j) > z){j--;}if (j >= 1 && customfunction.f(i, j) == z){res.add(Arrays.asList(i, j));}}return res;}
    }
    
    • 复杂度

      • 时间复杂度:O(C)O(C)O(C)CCC为x和y的取值范围,本题中为100010001000
      • 空间复杂度:$O(1) $
http://www.zhongyajixie.com/news/3192.html

相关文章:

  • 西安有什么好玩的有实力的网站排名优化软件
  • wordpress做的学校网站seo排名优化教学
  • 阿里云wordpress 备份数据武汉seo推广
  • 关于网站建设的书籍今天国内最新消息
  • 云端网站建设站长工具站长之家官网
  • 合山网站建设网络营销推广平台有哪些
  • 魏县网站制作天津疫情最新消息
  • 重庆市住房和城乡建设厅网站口碑营销的好处
  • 公司网站做么做百度排名草莓永久地域网名入2022
  • 牛商的网站后台国际新闻 军事
  • wordpress无法缩进seo是什么东西
  • 做网站封面要怎么做seo网站优化课程
  • 贵阳经济技术开发区网站百度推广怎么优化
  • 青岛黄页电话查询徐州seo顾问
  • 网页版传奇3baidu优化
  • 做零食的网站有哪些深圳网站设计公司哪家好
  • wordpress仿微信底部菜单cssseo百度快速排名软件
  • 网站建设docseo行业岗位有哪些
  • 网站建设策划自动化测试培训机构哪个好
  • 长治个人做网站seo好学吗
  • 分类信息网站建设企业网站建设模板
  • 企业网站内页设计seo视频网页入口网站推广
  • 手机网站推荐几个seo实战密码第三版pdf
  • 公众号运营工作内容抖音seo关键词优化排名
  • 视频嵌入网站网络优化工程师吃香吗
  • 深圳招聘一般在哪个网站网络平台营销
  • 辽宁建设工程信息网报名步骤郑州百度seo网站优化
  • 日本文创产品设计seo最强
  • 直播网站如何做怎么建免费网站
  • 万网免费建企业网站app开发费用一般多少钱