naved's blog

By naved, 10 years ago, In English

I have a problem for which I am not getting optimal answer from last 3 days Problem is as Below Given a graph G find the shortest distance between Source to Destination node but you MUST PASS THROUGH ALL THE NODES before going to destination BECAUSE THEY ALL are MUST_PASS nodes.

Additional info: - -you can pass any node more than once if required to get optimal answer - -max number of nodes is 22 including source & destination

What I tried so far - brute-force : simple permutation will give you the answer for small n , but since upper bound is 20, it is not practical 20! duhh :(

  • TSP with DP: problem with this is I Start from Source visit all nodes except destination & comes back to start, now if I go back to last node which I visited and from their if I go to destination one might think that this will give me optimal result, but the result is sub-optimal and not optimal ...:(

  • suppose each must_pass node is named as C, Start as S, destination as D, then one might thing f(S,D) = min(S,C1) + min(C1,C2) + min(C2,Ck) + min(Ck,D) but this is also sub-optimal and optimal for small graph with fewer MUST_VISIT nodes

Max Must_Visit nodes are 20

Full text and comments »

  • Vote: I like it
  • -6
  • Vote: I do not like it

By naved, 10 years ago, In English

Multiple “intervals” are to be given as tasks. Calculate the maximum work time (minutes) to assign to one worker

Implement the method “int Problem2#getMaxWorkingTime(List intervals)”.

  • Return the maximum time to work on a task when one worker takes it.
  • Time assignment unit shall be based on tasks. (i.e. Task assignment shall be either to complete the whole task, or to do nothing for it.)
  • The length of the interval, time required to complete the task, is calculated by subtracting "end time" from "start time". (e.g. If [12:00, 13:00] is given, the length of the task is 60 min.)
  • Return 0 if the argument is null or an empty list.
  • The argument (a list of “intervals”) must not contain null.
  • The number of “intervals” must not exceed 10,000

In Figure 3 , work time is maximized when three tasks [“06:00”, “08:30”], [“09:00”, “11:30”], and [“12:30”, “14:00”], are assigned. Therefore, the answer is 390 (minutes).

Figure 3: An example of input and answer

6     7     8     9     10      11      12       13       14
----------------  ---------------            ---------------
            -------         --------------------------------
                  -------------------

To me it appears to as a problem whose answer I can find simply by subtracting the Interval with max end-time i.e 14:00 with Interval which has smallest start-time, say 14:00 minus 06:00 answer is 480 minutes (since 6 to 14 has 8 hours in it so 8*60 minutes = 480 minutes) but the correct answer is 390 minutes Can any one please help me explaining how to solve this problem...?

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By naved, 11 years ago, In English

Hi guys, Since I have very tight schedule of my work therefore I am unable to register for rounds happening here at codeforce, so i just wanna know, is there any way in which i can come at any time solve some problems , upload code if accepted will yield me points ?

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it

By naved, 11 years ago, In English

I have submitted the code, the same code runs fine under my machine but it gives Test: #1, time: 124 ms., memory: 0 KB, exit code: 1, checker exit code: 0, verdict: RUNTIME_ERROR


/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package algorithms; import java.util.Scanner; /** * * @author Naved Momin<[email protected]/[email protected]> */ public class SimpleMath { class Node{ char data; Node left, right; } String data,op = ""; Node root; public void ALGO( ){ Scanner s = new Scanner(System.in); data = s.nextLine(); if( checker() == -1 ) System.out.println( data ); else { mkTree(); traverseTreeInorder(root); op = op.substring(0, op.length()-1); System.out.println(op); } } int checker( ){ return data.indexOf("+"); } public static void main(String[] args) { // TODO code application logic here new SimpleMath().ALGO(); } private void mkTree() { char[] toCharArray = data.toCharArray(); for (char c : toCharArray) { if( c != '+'){ tree( c ); } } } private void traverseTreeInorder(Node r) { if( r != null ){ traverseTreeInorder(r.left); op = op + r.data + "+"; traverseTreeInorder(r.right); } } private void tree(char c) { if( root == null ){ root = new Node(); root.data = c; }else{ Node r,p; r = p = root; int i,j; i = (int)c; while (r != null ) { p = r; j = (int)r.data; if( i < j ) r = r.left; else r = r.right; } r = new Node(); r.data = c; i = (int)r.data; j = (int)p.data; if( i < j ) p.left = r; else p.right = r; } } }

Full text and comments »

  • Vote: I like it
  • -4
  • Vote: I do not like it