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

绍兴建设局网站首页手机网站关键词seo

绍兴建设局网站首页,手机网站关键词seo,对自己做的网站总结,python语言特点原题链接 难度:middle\color{orange}{middle}middle 2023/2/18 每日一题 题目描述 给你一个函数 f(x,y)f(x, y)f(x,y) 和一个目标结果 zzz,函数公式未知,请你计算方程 f(x,y)zf(x,y) zf(x,y)z 所有可能的正整数 数对 xxx 和 yyy。满足条件…

原题链接

难度:middle\color{orange}{middle}middle

2023/2/18 每日一题


题目描述

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

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

  • f(x,y)<f(x+1,y)f(x, y) < f(x + 1, y)f(x,y)<f(x+1,y)
  • f(x,y)<f(x,y+1)f(x, y) < f(x, y + 1)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);
};

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

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

示例 1:

输入:function_id = 1, z = 5
输出:[[1,4],[2,3],[3,2],[4,1]]
解释:function_id = 1 暗含的函数式子为 f(x, y) = x + y
以下 x 和 y 满足 f(x, y) 等于 5:
x=1, y=4 -> f(1, 4) = 1 + 4 = 5
x=2, y=3 -> f(2, 3) = 2 + 3 = 5
x=3, y=2 -> f(3, 2) = 3 + 2 = 5
x=4, y=1 -> f(4, 1) = 4 + 1 = 5

示例 2:

输入:function_id = 2, z = 5
输出:[[1,5],[5,1]]
解释:function_id = 2 暗含的函数式子为 f(x, y) = x * y
以下 x 和 y 满足 f(x, y) 等于 5:
x=1, y=5 -> f(1, 5) = 1 * 5 = 5
x=5, y=1 -> f(5, 1) = 5 * 1 = 5

提示:

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

算法

(暴力枚举) O(n2)O(n^2)O(n2)

  1. 枚举 xy,调用接口判断 f(x, y) 是否等于 z

  2. 如果等于 z,则加入答案中,如果大于 z,则终止掉内层循环。

复杂度分析

  • 时间复杂度:最坏情况下,需要判断每一个数对,故时间复杂度为 O(n2)O(n^2)O(n2)

  • 空间复杂度 : 需要存储答案,故空间复杂度也为 O(n2)O(n^2)O(n2)

C++ 代码

/** // This is the custom function interface.* // You should not implement it, or speculate about its implementation* class CustomFunction {* public:*     // 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)*     int f(int x, int y);* };*/class Solution {
public:vector<vector<int>> findSolution(CustomFunction& customfunction, int z) {vector<vector<int>> res;for (int x = 1; x <= 1000; x ++) for (int y = 1; y <= 1000; y ++) if (customfunction.f(x, y) == z) {res.push_back({x, y});}return res;}
};

  • 双指针
/** // This is the custom function interface.* // You should not implement it, or speculate about its implementation* class CustomFunction {* public:*     // 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)*     int f(int x, int y);* };*/class Solution {
public:vector<vector<int>> findSolution(CustomFunction& customfunction, int z) {vector<vector<int>> res;int x = 1, y = 1000;while (x <= 1000 && y >= 1) {int t = customfunction.f(x, y);if (t > z) y --;else if (t < z) x ++;else {res.push_back({x, y});x ++, y --;}}return res;}
};
http://www.shuangfujiaoyu.com/news/8981.html

相关文章:

  • 什么网站有加工外发做的百度seo关键词排名优化工具
  • 做彩票网站非法吗google app下载
  • 电商网站零售客户四川聚顺成网络科技有限公司
  • php做的网站建设大连做优化网站哪家好
  • 12数据网站建设长尾词和关键词的区别
  • wordpress 页面顺序网站优化排名哪家性价比高
  • c .net网站开发如何进行搜索引擎优化
  • 网站建设合作网络安全培训机构排名
  • 做二手房又做网站的今日国际军事新闻
  • 百兆独享 做资源网站西安网络推广公司大全
  • 阜宁做网站哪家公司最好百度账户代运营
  • 青岛哪家做网站好网站建设的基本流程
  • 做网站 php java线上营销推广渠道
  • 勉费申请做网站成都网站快速优化排名
  • 网站建设便宜的公司网络上如何推广网站
  • 采购搜索引擎优化的目的是对用户友好
  • 公司是做网站建设的怎么开票百度快照搜索引擎
  • 阿里巴巴的电子商务网站建设培训机构是干什么的
  • java购物网站开发流程百度seo搜索引擎优化厂家
  • 网站上线之前做哪些工作北京网优化seo公司
  • mac做网站设计百度建站平台官网
  • 站长如何做导航网站网站底部友情链接代码
  • 贵州软件制作杭州seo推广优化公司
  • 做网站还要什么认证吗杭州龙席网络seo
  • 网站建设方案书 doc百度广告官网
  • 数码公司网站建设调查网站seo优化多少钱
  • 免费网站建设网站有那些找客户资源的软件哪个最靠谱
  • 如何获取免费域名网站运营优化培训
  • 公司名称logo设计图免费如何结合搜索检索与seo推广
  • 做肥料网站互联网品牌的快速推广