Tuesday, 8 October 2013

CodeChef October Challenge 2013 Editorial [Helping Lira]

Problem: Helping Lira
Given N triangles, each triangle is denoted by 6 coordinates (for 3 vertices), you have to print the indexes of the triangles with the smallest and largest area. If there are multiple solutions, print the last indexes.

Solution Idea:
as you know the coordinates of vertices, you can easily calculate area with this formula.
abs(0.5*((x2-x0)*(y1-y0)-(x1-x0)*(y2-y0)));
as you are comparing area of triangles, you need not to divided by 0.5. it offer you to solve the problem with 'int' data type.
no problem if you wish to use actual area.
now, Greedy approach to find the index of minimum and maximum area.
for last indexes:
tmp>=mx
if you were asked to print  first occurrece:
tmp>mx 

Code:
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int tc,kk=1, n, x0, x1, x2, y0, y1, y2;
  7. cin>>n;
  8. {
  9. int mn=1e9, mx=0, mni=0, mxi=0;
  10. for(int i=1;i<=n;i++)
  11. {
  12. cin>>x0>>y0>>x1>>y1>>x2>>y2;
  13. int tmp=abs((x2-x0)*(y1-y0)-(x1-x0)*(y2-y0));
  14. if(tmp>=mx)
  15. {
  16. mx=tmp;
  17. mxi=i;
  18. }
  19. if(tmp<=mn)
  20. {
  21. mn=tmp;
  22. mni=i;
  23. }
  24. }
  25. cout<<mni<<" "<<mxi<<endl;
  26. }
  27. return 0;
  28. }


Sunday, 6 October 2013

Some Interesting Programming Problems

Adhoc:
  1. Chocolate Feast
  2. Balloons
  3. Aladdin and the Optimal Invitation [O(n) adhoc solution exists, also solvable in nlogn using binary search]
  4. Stacks of Flapjacks
  5. Pole Position
Angular Sweeping:
  1. Photo Shoot 
Backtracking
  1. Turn the Lights Off  [Explanation]
  2. Another n-Queen Problem
  3. The Sultan's Successors [straightforward] 
Basic Data Structure:
  1. Flip It! [stack / vector]
  2. Wedding of Sultan [stack] [Editorial]
  3. Fence Repair [priority queue in reverse order]
  4. A and B and Interesting Substrings [map, pair]
  5. Parentheses Balance [stack]
Binary Search:
  1. Energetic Pandas [vector+lower bound, counting] 
  2. Haircut
Binary Indexed Tree:
  1. Cows
Binary Tree:
  1. Tree Summing [input to binary tree making]
Bitmask DP:
  1. Histogram
Bellman Ford:
  1. Travel Company
BFS:
  1. Number Transformation [i solved with dp]
  2. Chef and Digit Jumps [tricky bfs variant] 
  3. Prime Path
BigMod:
  1. One Unit Machine [Mod Inverse]
Bipartite Matching:
  1. Kamehameha [Editorial] 
Bridge:
  1. Street Directions
Brute Force:
  1. Be Efficient
  2. TheMatrix
Combinatorics:
  1. Colorful Board
  2. A Careful Approach (next permutation + binary search)
Computational Geometry:
  1. Laser Shot
Connected Component:
  1. Dominos 2 [undirected]
  2. Dominos [directed]
Counting:
  1. How Many Zeroes? [iterative and dp both solution exists]
Dijkstra:

  1. Not the best (2nd / kth)
  2. Almost Shortest Path (path track)

DFS:
  1. The Queue [dfs with combinatorics]
  2. Friends [straightforward dfs, wrong second sample output]
DP:
  1. Maximum Square
  2. nth Permutation
  3. Jogging Trails [Warshall+bitmask, Chinese Postman Problem]
  4. Chest of Drawers [basic]
  5. Dividing up [iterative dp with a little trick]
  6. Breaking Strings [Knuth's optimization, similar to Cutting Sticks with higher n]
  7. Antimatter
  8. Candy [0/1 knapsack, tricky]
  9. Lighted Panels [bitmask]
Floyd Warshall:
  1. Heavy Cargo (similar: The Tourist Guide, modified warshall)
Game Theory:
  1. Euclid's Game [ nim with a tricky observation]
Geometry:
  1. The Kissing Circles [solution]
Greedy:
  1. Sum the Square 
Histogram:
  1. Largest Rectangle in a Histogram
Implementation:
  1. Vitaly and Strings
  2. Arm Wrestling Tournament
Inclusion/Exclusion:
  1. 1144 - Ray Gun
KMP:

  1. Period [failure function only]

LCS:
  1. Vacation [straightforward lcs]

Math:
  1. Answering Queries
  2. Points in Figures: Rectangles, Circles, and Triangles [basic, tricks, precision check]
  3. Feynman 
Meet In The Middle:
  1. Coin Change (IV)
  2. 4 values whose sum is 0 (binary search / upper_bound, lower_bound)
Number Theory:
  1. Square-Free Numbers (factor power)
  2. How Many Points? (gcd)
  3. Garden Game (bigmod, prime factor)
  4. Big Number (log10)
  5. Divisors (number of divisors)
  6. Prime Factors [straightforward] 
Probability and Expected value:
  1. Game on Tree [+dfs]
Segment Tree:
  1. Meteor
  2. Sereja and Brackets
  3. Interval Product
Sieve:
  1. Help Hanzo [Segmented Sieve ]
  2. Printing some primes [bit seive]
Simulation:
  1. Basketball Game (queue)
  2. Billiard Balls
Sliding Window / Line Sweeping:
  1. Christmas Play [straightforward] [editorial]
  2. Broken Keyboard
  3. Sliding Window [classic, with explanation, beginner, deque]
Strongly Connected Components
  1. Proving Equivalences

Structure
  1. Wooden Sticks [STL pair]

Strongly Connected Component:
  1. Efficient Traffic System
  2. Forwarding Email
Trie
  1. XOR Sum ( cummulative XOR property: xor (L to R) = xor (1 to R) ^ xor (1 to L-1)
Union Find:

Thursday, 12 September 2013

Search Serial Key.

Get in google and search for "program name" 94FBRIn "program name"
write the name of the program that you want theserial for, without the ""

Friday, 19 July 2013

US University rankings for Master of Science in Computer Science Major (MS in CS) and PhD

1 MIT CAMBRIDGE
2 Stanford University STANFORD
3 University Of California-Berkeley BERKELEY
4 Carnegie Mellon University PITTSBURGH
5 Cornell University ITHACA
6 Princeton University PRINCETON
7 California Institute Technology PASADENA
8 University Of Texas At Austin AUSTIN
9 Harvard University CAMBRIDGE
10 Univ Of Illinois At Urbana,Champaign URBANA
11 University Of Wisconsin-Madison MADISON
12 Univ Of California,Los Angeles Los Angeles
13 Yale University New Haven
14 University Of Maryland College Park College Park
15 Brown University PROVIDENCE
16 University Of Washington SEATTLE
17 Univ Of Massachusetts At Amherst AMHERST
18 Rice University HOUSTON
19 University Of Southern California Los Angeles
20 University Of Michigan Ann Arbor
21 University Of Chicago CHICAGO
22 Georgia Institute Of Technology ATLANTA
23 New York University New York
24 University Of Pennsylvania PHILADELPHIA
25 Northwestern University EVANSTON
26 Purdue University West Lafayette
27 Univ Of California-San Diego San Diego
28 Rutgers State Univ-New Brunswick New Brunswick
29 Columbia University New York
30 Univ Of North Carolina-Chapel Hill Chapel Hill
31 University Of Rochester ROCHESTER
32.. State Univ Of New York-Stony Brook Stony Brook
33 University Of Arizona TUCSON
34 Duke University DURHAM
35 University Of California-Irvine IRVINE
36 University Of Virginia CHARLOTTESVILLE
37 Indiana University BLOOMINGTON
38 Ohio State University COLUMBUS
39 Syracuse University SYRACUSE
40 University Of Colorado BOULDER
41 Johns Hopkins University BALTIMORE
42 Oregon Graduate Inst Sci & Tech BEAVERTON
43 Pennsylvania State University University Park
44 University Of Pittsburgh PITTSBURGH
45 University Of Pennsylvania PHILADELPHIA
46 University Of Minnesota MINNEAPOLIS
47 Virginia Polytech Inst & State U BLACKSBURG
48 Texas A&m University College Station
49 Rensselaer Polytechnic Inst TROY
50 University Of Florida GAINESVILLE