CHPLGNS - Editorial

@rajavineel: Your solution looks not for the maximum of abs(x-coords), but of for the maximum of both x and y ones.

Please tell me whats wrong with this solution ?
http://www.codechef.com/viewsolution/7235511

@rajavineel , you and me were doing similar mistake. FORGETTING TO CLEAR THE VECTOR !!! :slight_smile: :slight_smile:

My code gives AC for 6 cases, and WA for 9. I cant figure out why. Im finding area and then sorting wrt to area.
Any help?
my code - gCORiI - Online C++ Compiler & Debugging Tool - Ideone.com

EDIT - converted int to long long… got AC. FML

@birdofprey. Having similar issues. I was using point-in-polygon test by finding the winding number. Actually, I did this twice actually with two very different algorithms (one by taking total angle sum, one by tracking movement between quadrants), but got AC on only half of the test cases – same WA for both algorithms, which seems suspicious. Highly suspect bad test cases.

@sid_sp123. Gets the bounding box of this Polygon. The bounding box is the smallest Rectangle whose sides are parallel to the x and y axes of the coordinate space, and can completely contain the Polygon.

since is a rectangle, there can be a polygon that lies inside this rectangle, but lies outside the polygon. your code would fail there

I used the logic that the perimeter of the inner polygon is less than the perimeter of the outer rectangle, and as usual sorted it and found out the answer

can anybody point out error in my solution?? i used the same approach as described in this tutorial(area sorting) but getting ac partially :frowning:

http://www.codechef.com/viewsolution/7183272

calculating the max area approach might fail if do not consider origin as the centre of each polygon.
lets say the triangle given in problem have the same area but is shifted so that it comes out of both the polygon.
In that case this method fails according to me… please correct me if i am going wrong somewhere…

I solved this problem by calculating area using the shoelace formula and then sorting, it managed to pass all test cases although I think the editorial solution is better.

In the question, are they assuming that the centre or centroid of the polygon lies on the centre?

@njr07121977 You are wrong: perimeter of the enclosed polygon does not have to be smaller than perimeter of the enclosing one. If this solultion passed, it means that test-cases were poorly prepared (and as it is stated in my and some other comments above, it is highly probable, that some test-cases were just wrong and violated problem statement).

I sorted the array in ascending order and then compared it to the original array to get the answer the rest of the logic is same but its showing wrong answer plz help me with this my code

http://www.codechef.com/viewsolution/7248204

very good tutorial i hav ever seeen thanks to balaji…

I did the same thing, but I am getting WA for most of the cases. Although few cases are accepted. Please someone tell me what is wrong with my solution- CodeChef: Practical coding for everyone

pls help me why I am getting nZEC for the following code

import java.io.IOException;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.Map;

public class Main {

public static void main(String[] args) throws IOException  {
    Scanner sc = new Scanner(System.in);
     int t = sc.nextInt();
     while(t-->0)
     {
        Main ob = new Main();
        ob.disp();
     }
}
void disp()throws IOException
{
   Scanner in = new Scanner(System.in);  
   int n =in.nextInt();
   TreeMap<Integer,Integer> tm = new TreeMap<>();
   int i =0;
   int [] ans= new int[n];
   int l = n;
   while(n-->0)
   {
       int min =1000008;
       int m = in.nextInt();
       i++;
       while(m-->0)
       {
          int x =in.nextInt(); 
           int y =in.nextInt();
           min = Math.min(min,x);
       }
       tm.put(min,i);
   }
   int r=l-1;
  
   for(Map.Entry<Integer,Integer> entry: tm.entrySet())
   {
       int k= entry.getValue();
        System.out.println(k);
      ans[k-1]= r;
      r--;
   }
   for(int j=0;j<l;j++)
   {
       System.out.print(ans[j]+" ");
   }
    System.out.println();
}

}

What if there are two polygons and first polygon coordinates are (0,0) (1,0) (1,1) and (0,1) and second polygon coordinates are (0,0) (-1,0) (-1,-1) and (0,-1).
So according to your algorithm what I understood is if you sort these two polygons then second polygon which lesser max x coordinate will lie in first polygon but actually its not lying.
Can somebody help me where I am going wrong.

@kartik7153
If you are reading the practice version of this problem then it doesn’t contain enough information in it. Refer to the competition version of the problem description as that has been updated with extra information. Refer to the first paragraph where it states that no two polygons shall intersect with each other so your example isn’t a valid test example. Also polygon P1 is either completely inside another polygon P2 or P2 is completely inside P1. This applies for all polygons. Have a look at the diagram in the problem and you will see that the polygons are all inside of each other, this simplifies the problem a lot.

Also the questions and answers in the competition version of the problem give more explanation which may help you understand the exact constraints for the polygons.

Highest x-coordinate! Wow, never thought of that :slight_smile:

The error was that I did not clear the vector. Thanks sumitjha4321 for pointing the error. It works now.