Junior Programming Camp BUET 2016 -Day1 contest Geometry & String editorial (Only for beginners)

Правка en1, от Farsid, 2016-01-07 15:49:38

Contest Link:

You can also download the entire editorial from [here].(https://www.dropbox.com/s/yqpp02s461wucwq/Junior-Programming-Camp-BUET-2016-Day-3-Editorial.pdf?dl=0)

Problem A: SPOJ BSHEEP

Have to find the convex hull of the points. An O(n logn) approach is required as ‘n’ is large. Use Graham’s scan to find the convex hull. Pretty straight forward. Avoid floating point calculations as much as possible. This problem offers all annoying details one can think of(collinear points, repeated point coordinates, less-than-3-point inputs,...). When all the points are collinear, you have to return twice the distance between the furthest pair.

Solution

Problem B: LightOJ-1129(Consistency Checker)

This problem can be solved by the data structure named TRIE. Those who haven’t come across this algorithm please read this [blog].(http://www.shafaetsplanet.com/planetcoding/?p=1679)All you need to do is push all the strings into the trie and later check if all the endpoints of the strings are leaves of the trie tree. This problem can also be solved by hashing. First we precalculate the hash value of all the indices of all strings. Then for each string we check if there is any other string whose prefix of equal length has the same hash value as our given string.

Solution

Problem C: LightOJ-1137(Expanding Rods)

We get two equations here: L' = r1 * ang; L = 2 * r2 * sin(ang/2); where ang is the angle subscribed by the arc L’ at the centre. Now we binary search on r (r1==r2) to obtain the value of ang and the final answer is r — r*cos(ang/2).

Solution

Problem D: Codechef Shift The String

This was the only problem on KMP in the contest. Due to technical problems, this problem statement was not properly visible, but this problem is worth solving. Let's say we append string B at the end of string B. We get: B1,B2...BN B1,B2...BN. The thing worth noting is that after K shift operations we get BK+1,BK+2...BN,B1,B2...BK. This string(which we get after K shift operations) is now a substring of the new string that we got by appending B at the end of B.
KMP helps us in finding all prefixes of a string X in string Y. So we'll search A in B.B(means concatanation of B with B) which will help us in knowing which prefixes of A are present in B. We'll choose an answer that gives us the largest prefix, also it'll give the index at which that prefix matches, from which we can find the number of shifts required.

Solution

Problem E: LightOJ 1224

This is another problem that requires TRIE. Insert all the strings into the trie and keep a counter how many times each node is visited. Each time while visiting a node update the answer with max(answer, depth of node*number of times the node is visited) .

Solution

Problem F: LightOJ 1258(Making Huge Palindromes)

With Manacher’s algorithm find the length of the longest palindrome that finishes at the last character of the string. If this length is ‘a’ and the size of the string is ‘sz’ then the smallest length that needs to be appended to make the string a palindrome is (2*sz-a).

Solution

Problem G: LightOJ 1267(POINTS IN RECTANGLE- II)LightOJ 1267(POINTS IN RECTANGLE- II)

Compress the y coordinates(so that you can use a data structure like BIT or segment tree) . The DS will keep track of the y coordinate;ie, if j’th position in your DS has value 2 that means until now we have found 2 points as having ‘j’ as ordinate. Now line sweep from left to right. When you encounter a point, increase the count in your data structure(BIT) by 1. When you encounter start edge of a rectangle, say it stretches from y1 to y2, keep track of the number of points that occur between y1 to y2 until now. These are the points that occur between y1 to y2 but are located to the left of starting edge of the rectangle and thus outside the rectangle. When you encounter the finishing edge of a rectangle, say it also stretches from y1 to y2, find the number of points that occur between y1 to y2 . These are all the points that occur to the left of finishing edge, and thus may occur inside or outside the rectangle. Remember, we kept track of the number of points occurring to the left of the starting edge of the rectangle which are outside the rectangle. Therefore, number of points inside the rectangle = number of points to the left of finishing edge(within y1 to y2) — number of points to the left of starting edge(within y1 to y2). Use the DS to find out the number of points within y1 to y2.

Solution

Problem H: POJ HOTTER COLDER

This problem is straight forward implementation of half planes.

Solution

Problem I: Weakness and Poorness

F(x)=max(abs(a1-x),abs(a2-x),…,abs(an-x)) Here we have to find the value of x for which F(x) is minimum.

A little observation will help you find out that F(x) is a convex function(not exactly convex, but lets use this word anyway). Use Ternary Search to obtain the value of ‘x’, for which f(x) is minimum.

Solution Link

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский Farsid 2016-01-07 16:13:11 2
en5 Английский Farsid 2016-01-07 16:07:33 0 (published)
en4 Английский Farsid 2016-01-07 16:06:29 3
en3 Английский Farsid 2016-01-07 16:05:49 39
en2 Английский Farsid 2016-01-07 16:03:12 1748
en1 Английский Farsid 2016-01-07 15:49:38 6055 Initial revision (saved to drafts)