Note that there are some explanatory texts on larger screens.

plurals
  1. POMinimize maximum absolute difference in pairs of numbers
    primarykey
    data
    text
    <p><strong>The problem statement</strong>:<br> Give <code>n</code> variables and <code>k</code> pairs. The variables can be distinct by assigning a value from 1 to <code>n</code> to each variable. Each pair <code>p</code> contain 2 variables and let the absolute difference between 2 variables in <code>p</code> is <code>abs(p)</code>. Define the upper bound of difference is <code>U=max(Abs(p)|every p)</code>. </p> <p>Find an assignment that minimize <code>U</code>. </p> <pre><code>Limit: n&lt;=100 k&lt;=1000 </code></pre> <p>Each variable appear at least 2 times in list of pairs.</p> <pre><code>A problem instance: Input n=9, k=12 1 2 (meaning pair x1 x2) 1 3 1 4 1 5 2 3 2 6 3 5 3 7 3 8 3 9 6 9 8 9 Output: 1 2 5 4 3 6 7 8 9 (meaning x1=1,x2=2,x3=5,...) </code></pre> <p><strong>Explaination:</strong> An assignment of <code>x1=1,x2=2,x3=3,...</code> will result in <code>U=6</code> (3 9 has greastest abs value). The output assignment will get <code>U=4</code>, the minimum value (changed pair: <code>3 7 =&gt; 5 7, 3 8 =&gt; 5 8</code>, etc. and 3 5 isn't changed. In this case, <code>abs(p)&lt;=4</code> for every pair). </p> <p><strong>There is an important point</strong>: To achieve the best assignments, the variables in the pairs that have greatest abs must be change.<br> Base on this, I have thought of a greedy algorithm: </p> <pre><code>1)Assign every x to default assignment (x(i)=i) 2)Locate pairs that have largest abs and x(i)'s contained in them. 3)For every i,j: Calculate U. Swap value of x(i),x(j). Calculate U'. If U'&lt;U, stop and repeat step 3. If U'&gt;=U for every i,j, end and output the assignment. </code></pre> <p>However, this method has a major pitfall, if we need an assignment like this: </p> <pre><code>x(a)&lt;&lt;x(b), x(b)&lt;&lt;x(c), x(c)&lt;&lt;x(a) </code></pre> <p>, we have to swap in 2 steps, like: <code>x(a)&lt;=&gt;x(b)</code>, then <code>x(b)&lt;=&gt;x(c)</code>, then there is a possibility that <code>x(b)&lt;&lt;x(a)</code> in first step has its abs become larger than U and the swap failed.<br> Is there any efficient algorithm to solve this problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload