<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brute Force Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/category/brute-force/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/category/brute-force/</link>
	<description></description>
	<lastBuildDate>Mon, 28 Oct 2019 03:18:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>Brute Force Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/category/brute-force/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1237. Find Positive Integer Solution for a Given Equation</title>
		<link>https://zxi.mytechroad.com/blog/brute-force/leetcode-1237-find-positive-integer-solution-for-a-given-equation/</link>
					<comments>https://zxi.mytechroad.com/blog/brute-force/leetcode-1237-find-positive-integer-solution-for-a-given-equation/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 28 Oct 2019 03:16:56 +0000</pubDate>
				<category><![CDATA[Brute Force]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[O(mn)]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5785</guid>

					<description><![CDATA[<p>Given a&#160;function&#160;&#160;f(x, y)&#160;and a value&#160;z, return all positive integer&#160;pairs&#160;x&#160;and&#160;y&#160;where&#160;f(x,y) == z. The function is constantly increasing, i.e.: f(x, y) &#60; f(x + 1, y) f(x,&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/brute-force/leetcode-1237-find-positive-integer-solution-for-a-given-equation/">花花酱 LeetCode 1237. Find Positive Integer Solution for a Given Equation</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Given a&nbsp;function&nbsp;&nbsp;<code>f(x, y)</code>&nbsp;and a value&nbsp;<code>z</code>, return all positive integer&nbsp;pairs&nbsp;<code>x</code>&nbsp;and&nbsp;<code>y</code>&nbsp;where&nbsp;<code>f(x,y) == z</code>.</p>



<p>The function is constantly increasing, i.e.:</p>



<ul><li><code>f(x, y) &lt; f(x + 1, y)</code></li><li><code>f(x, y) &lt; f(x, y + 1)</code></li></ul>



<p>The function interface is defined like this:&nbsp;</p>



<pre class="wp-block-preformatted;crayon:false">interface CustomFunction {
public:
&nbsp; // Returns positive integer f(x, y) for any given positive integer x and y.
&nbsp; int f(int x, int y);
};
</pre>



<p>For custom testing purposes you&#8217;re given an integer&nbsp;<code>function_id</code>&nbsp;and a target&nbsp;<code>z</code>&nbsp;as input, where&nbsp;<code>function_id</code>&nbsp;represent one function from an secret internal list, on the examples you&#8217;ll know only two functions from the list. &nbsp;</p>



<p>You may return the solutions in any order.</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> function_id = 1, z = 5
<strong>Output:</strong> [[1,4],[2,3],[3,2],[4,1]]
<strong>Explanation:</strong>&nbsp;function_id = 1 means that f(x, y) = x + y</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> function_id = 2, z = 5
<strong>Output:</strong> [[1,5],[5,1]]
<strong>Explanation:</strong>&nbsp;function_id = 2 means that f(x, y) = x * y
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= function_id &lt;= 9</code></li><li><code>1 &lt;= z &lt;= 100</code></li><li>It&#8217;s guaranteed that the solutions of&nbsp;<code>f(x, y) == z</code>&nbsp;will be on the range&nbsp;<code>1 &lt;= x, y &lt;= 1000</code></li><li>It&#8217;s also guaranteed that&nbsp;<code>f(x, y)</code>&nbsp;will fit in 32 bit signed integer if&nbsp;<code>1 &lt;= x, y &lt;= 1000</code></li></ul>



<h2><strong>Solution1 : Brute Force</strong></h2>



<p>Time complexity: O(1000*1000)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;vector&lt;int&gt;&gt; findSolution(CustomFunction&amp; customfunction, int z) {
    vector&lt;vector&lt;int&gt;&gt; ans;    
    for (int x = 1; x &lt;= 1000; ++x) {
      if (customfunction.f(x, 1) &gt; z) break;
      for (int y = 1; y &lt;= 1000; ++y) {
        int t = customfunction.f(x, y);
        if (t &gt; z) break;
        if (t == z) ans.push_back({x, y});        
      }
    }
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/brute-force/leetcode-1237-find-positive-integer-solution-for-a-given-equation/">花花酱 LeetCode 1237. Find Positive Integer Solution for a Given Equation</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/brute-force/leetcode-1237-find-positive-integer-solution-for-a-given-equation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
