ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1469. No Smoking!

What's the "good" algo for this problem
Posted by Todor Tsonkov 25 Sep 2006 01:03
I coded for 10 minutes brute force which got TL on test 4.. any ideas about the "good" algo ?
Re: What's the "good" algo for this problem
Posted by Ilya Rasenstein (Lyceum #40) 25 Sep 2006 21:04
Surely! std::set 4ever!
Re: What's the "good" algo for this problem
Posted by Todor Tsonkov 25 Sep 2006 21:32
Haha :) Some more hints ;)
Read Cormen's "Introduction to Algorithms" (-)
Posted by Vladimir Yakovlev (USU) 25 Sep 2006 23:36
Re: Read Cormen's "Introduction to Algorithms" (-)
Posted by Ilya Rasenstein (Lyceum #40) 26 Sep 2006 10:54
You can implement stuff, described in Cormen, easily, using set. That's what I was trying to say.
Ilya Razenshteyn.
Re: Read Cormen's "Introduction to Algorithms" (-)
Posted by Vedernikoff Sergey 6 Oct 2006 13:41
There is obvious "slide line" algo, that can be applied in O(NlogN). But there is a little problem here: perpendicular to ox line segments...
Re: Read Cormen's "Introduction to Algorithms" (-)
Posted by EfremovAleksei 13 Nov 2006 16:35
It's not problem! I don't exam this case and got AC.
No subject
Posted by Todor Tsonkov 15 Nov 2006 14:31
Can you explain a little more about this algo ?
Re: Read Cormen's "Introduction to Algorithms" (-)
Posted by Thunder 1 Apr 2007 16:13
This isn't problem too. Just rotate all points by the constant angle.

const
  angle=pi/60;
var
  x,y,buf1,buf2:real;
begin
...
  Buf1:=x;
  Buf2:=y;
  x:=Buf1*cos(angle)-Buf2*sin(angle);
  y:=Buf1*sin(angle)+Buf2*cos(angle);

Edited by author 01.04.2007 16:14
Re: Read Cormen's "Introduction to Algorithms" (-)
Posted by svr 13 Jul 2007 17:09
I solved for me the little problem of vertical segments by
applying affine matrix
[2 3]
[5 -7]
or any other to given coordinates.
As result algo from Cormen can be taken without any changes.

Edited by author 13.07.2007 17:09
Re: Read Cormen's "Introduction to Algorithms" (-)
Posted by Lomir 14 Jul 2007 00:43
As far as me, I used some my heuristics with vertical segments:
First, when reading points i makred point with lesser x cordinate as enter point.
I sorted points by X, and if X are eual then sorted by enter mark.
This assumes then enterpoint will be before exitpoint of segment in set.
Re: Read Cormen's "Introduction to Algorithms" (-)
Posted by Denis Koshman 30 Aug 2008 04:41
Vertical segments are easy to treat. Just sort X ascendingly and for equal X sort Y ascendingly. When you add vertical segment, consider its topmost Y coordinate during comparisons, and when you add some other segment, assume equality when its scan-line ordinate is compared to that one of vertical segment in the set.

Such behavior is identical to the one we'd apply to the segments set after rotating it for small enough angle. Another way to see that - apply skew affine transform

x2 = x+y*1e-6
y2 = y

and see how formerly vertical segments are handled in this case.

Edited by author 30.08.2008 04:52