11106 - Rectilinear Polygon

All about problems in Volume 111. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

vinay
Experienced poster
Posts: 104
Joined: Thu Apr 13, 2006 2:26 pm
Location: India
Contact:

Post by vinay »

thanks I will try it myself at least for few hours...
before further assistance..
If I will myself do hashing, then who will do coding !!!
navid_a2b
New poster
Posts: 10
Joined: Mon Oct 02, 2006 4:32 pm
Location: Tehran,Iran
Contact:

Post by navid_a2b »

thanks little joey !

I got AC thiniking on your input set :D
rammestain
New poster
Posts: 18
Joined: Fri Apr 21, 2006 11:34 am

Post by rammestain »

how can I chek that is the polygon simple or not?
I think if I want check for it , my program will get TLE
vinay
Experienced poster
Posts: 104
Joined: Thu Apr 13, 2006 2:26 pm
Location: India
Contact:

Post by vinay »

@little joey...

ok gave up...
what additonal step r u talking about.... :oops:
If I will myself do hashing, then who will do coding !!!
gvcormac
Problemsetter & Reviewer
Posts: 194
Joined: Fri Mar 15, 2002 2:00 am
Contact:

Post by gvcormac »

rammestain wrote:how can I chek that is the polygon simple or not?
I think if I want check for it , my program will get TLE
Good question. The test data for this problem is too weak.
vinay
Experienced poster
Posts: 104
Joined: Thu Apr 13, 2006 2:26 pm
Location: India
Contact:

Post by vinay »

u mean simulating the process of choosing point would suceed ....

but i don't wanna do that....

@little joey

what additonal step is required...
If I will myself do hashing, then who will do coding !!!
gvcormac
Problemsetter & Reviewer
Posts: 194
Joined: Fri Mar 15, 2002 2:00 am
Contact:

Post by gvcormac »

vinay wrote:u mean simulating the process of choosing point would suceed ....

but i don't wanna do that....

@little joey

what additonal step is required...
Label all possible points (there are only 4 million of them) with their
minimum distance from mall A. From these chose the closest one
that is a point on mall B. You can do this in o(4 million) operations.
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

vinay wrote:@little joey

what additonal step is required...
I'm sorry, but my algorithm is incorrect (although I get Accepted), for the reason rammestain mentioned. For the input

Code: Select all

1
6
0 0
1 0
0 1
2 1
1 2
2 2 
it gives 8, but the resulting polygon is not simple. So either the testdata is too simple, or it is not correct. I'm afraid I can't help you until I've corrected my own program...
gvcormac
Problemsetter & Reviewer
Posts: 194
Joined: Fri Mar 15, 2002 2:00 am
Contact:

Post by gvcormac »

little joey wrote:
vinay wrote:@little joey

what additonal step is required...
I'm sorry, but my algorithm is incorrect (although I get Accepted), for the reason rammestain mentioned. For the input

Code: Select all

1
6
0 0
1 0
0 1
2 1
1 2
2 2 
it gives 8, but the resulting polygon is not simple. So either the testdata is too simple, or it is not correct. I'm afraid I can't help you until I've corrected my own program...
Yes the test data is too simple. So one possible "fix" is to reword the question ... but it isn't that easy: you have to replace non-intersecting by something like "distinct vertices and any pair of edges share at most one point"

If you insist on implementing the problem as specified, you have to worry about segment intersection. There are algorithms for this but sub-quadratic is complicated.
lost
New poster
Posts: 11
Joined: Wed Oct 04, 2006 9:16 pm

Post by lost »

one easy way to check if resulting polygon is 'simple' is to start from any point and move along lines , flagging points as you go, untill you hit already flagged point.

then you just check if in that process you flaged all points.

of course, it rely on being able to see which points are connected, but that is usually what your first part of solution does when you try to create polygon ;p

anyway, this approach is fast enough - even if you use PASCAL as I did
gvcormac
Problemsetter & Reviewer
Posts: 194
Joined: Fri Mar 15, 2002 2:00 am
Contact:

Post by gvcormac »

lost wrote:one easy way to check if resulting polygon is 'simple' is to start from any point and move along lines , flagging points as you go, untill you hit already flagged point.

then you just check if in that process you flaged all points.

of course, it rely on being able to see which points are connected, but that is usually what your first part of solution does when you try to create polygon ;p

anyway, this approach is fast enough - even if you use PASCAL as I did
Your approach fails to check for self-intersection.
lost
New poster
Posts: 11
Joined: Wed Oct 04, 2006 9:16 pm

Post by lost »

i think that first part of my solution, one that generate polygon, can not generate self-intersecting one

but i will have to check that ;p
lost
New poster
Posts: 11
Joined: Wed Oct 04, 2006 9:16 pm

Post by lost »

ah, i just found that my approach for generating polygon CAN generate self-intersecting polygons, as gvcormac suggested ;p

one simple test case would be:

1
6
0 0
0 1
1 0
1 2
2 1
2 2


anyway, it turned out that i had only slightly to modify my algorithm in order to detect if there is some line crossing during polygon creation. It even run at about same speed as previous one (was x53, now its x55)
gvcormac
Problemsetter & Reviewer
Posts: 194
Joined: Fri Mar 15, 2002 2:00 am
Contact:

Post by gvcormac »

lost wrote:ah, i just found that my approach for generating polygon CAN generate self-intersecting polygons, as gvcormac suggested ;p

one simple test case would be:

1
6
0 0
0 1
1 0
1 2
2 1
2 2


anyway, it turned out that i had only slightly to modify my algorithm in order to detect if there is some line crossing during polygon creation. It even run at about same speed as previous one (was x53, now its x55)
Again, the test data is too weak. A quadratic time solution to line crossing should not be fast enough.
lost
New poster
Posts: 11
Joined: Wed Oct 04, 2006 9:16 pm

Post by lost »

well, i'm not using quadratic time solution to detect line crossing. solution that i used is fast enough, but it rely on same assumption that rest of my solution rely on.

as long as that assumption is correct, my intersection detection will work fast.

if that assumption is invalidated by changing test data, then not only my intersection will not work, but rest of my solution as well

and since that assumption is not something that i would normally assume for test data (in fact, my first solution did not assume it, and it had TE), i would have to agree with you that test data is weak ;p
Post Reply

Return to “Volume 111 (11100-11199)”