Note that there are some explanatory texts on larger screens.

plurals
  1. POImprove efficiency "lighthouse"
    primarykey
    data
    text
    <p>Problem Description:</p> <p>There are many light house in the sea. The range of the sea is <code>[1, 10^7] × [1, 10^7]</code>.</p> <p>Each light house can light up the south-west and north-east area. The power of the light is enought to cover any distance.</p> <p><img src="https://i.stack.imgur.com/CRYo9.png" alt="enter image description here"></p> <p>If the light house A and B are in there lighting up area, says they can illuminate each other.</p> <p>input has n+1 lines: the first line is the number of light house. the second line to the n<em>th</em> line are the horizontal and vertical coordinate of the light house.</p> <p>output has one line: the pair of light house which can illuminate each other.</p> <p>for example:</p> <p>intput:</p> <pre><code>3 2 2 4 3 5 1 </code></pre> <p>output:</p> <pre><code>1 </code></pre> <p>note:</p> <p>The coordinate of the light house is int. The horizontal and vertical coordinate of all the light houses are different.</p> <pre><code>1 ≤ x, y ≤ 10^7 </code></pre> <p>the efficiency of my code is very low. Please help me revise my code. Thank you very much!</p> <p>Here is my code. </p> <pre><code> #include&lt;stdlib.h&gt; int main() { int n,i,j,s; int *x,*y; scanf("%d",&amp;n); x=(int *)malloc(n*sizeof(int)); y=(int *)malloc(n*sizeof(int)); for(i=0;i&lt;n;i++) { scanf("%d %d",&amp;x[i],&amp;y[i]); } s=0; for(i=0;i&lt;n-1;i++) for(j=i+1;j&lt;n;j++) { if((x[i]&gt;x[j]&amp;&amp;y[i]&gt;y[j])||(x[i]&lt;x[j]&amp;&amp;y[i]&lt;y[j])) s++; } printf("%d\n",s); free(x); free(y); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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