Page 1 of 1

11586 - Train Tracks

Posted: Tue Mar 03, 2009 11:31 pm
by shiplu_1320
if no of pieces> 1 and no of MM == no of FF then there is a loop,
otherwise no loop.

someone give a counterexample.
waiting....

Re: 11586 - Train Tracks

Posted: Wed Mar 04, 2009 8:00 am
by sohel
There is no counterexample!
What you said is correct.

Re: 11586 - Train Tracks

Posted: Wed Mar 04, 2009 12:07 pm
by shiplu_1320
So, why this code is getting WA...

Code: Select all

Removed after AC

Re: 11586 - Train Tracks

Posted: Wed Mar 04, 2009 2:59 pm
by sohel
pieces=0; should be inside the while() loop, shouldn't it?

Re: 11586 - Train Tracks

Posted: Wed Mar 04, 2009 3:17 pm
by shiplu_1320
ops! :oops: , Sorry for disturb :oops: :oops: :oops:

Re: 11586 - Train Tracks

Posted: Fri Apr 03, 2009 1:48 am
by aliahmed
got TLE why?

Removed after ACC

You can do it simply by counting male & female conector.

if male conector equals to female conector then LOOP other wise NO LOOP
And also if there is only one conector then it will be no loop..

Re: 11586 - Train Tracks

Posted: Fri Apr 03, 2009 6:13 am
by MRH
hi "aliahmed" your code not only TLE this is also Wrong methode.
read the problem again and try to find proper solution.
thanks

Re: 11586 - Train Tracks

Posted: Sat Sep 05, 2009 6:40 pm
by saiful_sust
u can do it with simple dp.....
or easy adhoc...........

read the problem carefully and solve it.... :roll:

Re: 11586 - Train Tracks

Posted: Thu May 27, 2010 5:19 pm
by Taman
@Aliahmed:
You can do it simply by counting male & female conector.

if male conector equals to female conector then LOOP other wise NO LOOP
Well then consider the case,
1
MF FM
What should be the output? Or have I misunderstood the problem? My AC program gives "NO LOOP" as output, and I think it should be. But according to your post, it should be "LOOP".

Re: 11586 - Train Tracks

Posted: Mon Dec 23, 2013 9:49 am
by uDebug
I found these test cases useful during my testing / debugging for this problem.

Input:

Code: Select all

8
MF MF
FM FF MF MM
MM FF
MF             MF MF MF           FF
MF FM
FM MF MF FM MF
FM MF MF FF MM FF
FM
AC Output:

Code: Select all

LOOP
LOOP
LOOP
NO LOOP
LOOP
LOOP
NO LOOP
NO LOOP

Re: 11586 - Train Tracks

Posted: Mon Aug 11, 2014 6:21 pm
by Zyaad Jaunnoo
if no of pieces> 1 and no of MM == no of FF then there is a loop,
otherwise no loop.

someone give a counterexample.
waiting....
Just to make your statement more robust, consider the case where you have the only 2 pieces: MF FM.
Here, no. of MM = no. of FF = 0.
However, in such case, there is no loop.

Re: 11586 - Train Tracks

Posted: Wed Dec 24, 2014 5:41 pm
by lighted
Zyaad Jaunnoo wrote:
if no of pieces> 1 and no of MM == no of FF then there is a loop,
otherwise no loop.

someone give a counterexample.
waiting....
Just to make your statement more robust, consider the case where you have the only 2 pieces: MF FM.
Here, no. of MM = no. of FF = 0.
However, in such case, there is no loop.

Code: Select all

1
MF FM
My accepted code returns "LOOP" for this case (same as uDebug and uvatoolkit)

Re: 11586 - Train Tracks

Posted: Sat Dec 27, 2014 11:38 pm
by Zyaad Jaunnoo
lighted wrote:

Code: Select all

1
MF FM
My accepted code returns "LOOP" for this case (same as uDebug and uvatoolkit)
Indeed strange. However, logically we should not be able to make a loop.
Am I correct?

Re: 11586 - Train Tracks

Posted: Tue Dec 30, 2014 9:18 am
by lighted
I think problem description is not clear enough. As i understood with given picture of track pieces in problem description we can turn a piece FM to MF or MF to FM. But this should be said in problem description clearly.

Re: 11586 - Train Tracks

Posted: Wed Jan 27, 2016 5:21 am
by arorag2396
Can anyone help me why i am getting wrong answer??


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

class Main {

public static void main(String[] args) throws FileNotFoundException {

Scanner cin = new Scanner(System.in);
//Scanner cin = new Scanner(new FileInputStream(args[0]));


int n = Integer.parseInt(cin.nextLine());



for (int i = 0; i < n; i++) {
String s ;

s = cin.nextLine();
s = s.trim().replaceAll(" +", " ");




boolean isItTrue = true;
int m1=0;
int mfs[] = new int[4];//mm==0,ff==1,mf=2,fm=3

for(int ma=0;ma<4;ma++)
mfs[ma] = 0;

for (int j = 0; j < s.length() -1 ; j += 3) {

switch (s.subSequence(j, j + 2)+""){

case "MM" :
mfs[0]++;break;
case "FF" :
mfs[1]++;break;
case "MF" :
mfs[2]++;break;
case "FM" :
mfs[3]++;break;


}
m1++;

}

if(m1<2)
{

isItTrue = false;
}


if((mfs[0]!=mfs[1] ))
isItTrue = false;




if(isItTrue)
System.out.println("Loop");
else
System.out.println("No Loop");





}

}

}