## 11586 - Train Tracks

Moderator: Board moderators

shiplu_1320
New poster
Posts: 32
Joined: Sat Dec 29, 2007 9:08 pm
Location: CSEDU , Dhaka
Contact:

### 11586 - Train Tracks

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....
Last edited by shiplu_1320 on Fri Apr 03, 2009 11:29 am, edited 1 time in total.
A learner......

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

### Re: 11586 - Train Tracks

There is no counterexample!
What you said is correct.

shiplu_1320
New poster
Posts: 32
Joined: Sat Dec 29, 2007 9:08 pm
Location: CSEDU , Dhaka
Contact:

### Re: 11586 - Train Tracks

So, why this code is getting WA...

Code: Select all

``````Removed after AC
``````
Last edited by shiplu_1320 on Wed Mar 04, 2009 3:18 pm, edited 1 time in total.
A learner......

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

### Re: 11586 - Train Tracks

pieces=0; should be inside the while() loop, shouldn't it?

shiplu_1320
New poster
Posts: 32
Joined: Sat Dec 29, 2007 9:08 pm
Location: CSEDU , Dhaka
Contact:

### Re: 11586 - Train Tracks

ops! , Sorry for disturb
A learner......

aliahmed
New poster
Posts: 24
Joined: Fri Oct 24, 2008 8:37 pm
Contact:

### Re: 11586 - Train Tracks

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..
Last edited by aliahmed on Wed Sep 09, 2009 8:03 pm, edited 1 time in total.

MRH
Learning poster
Posts: 51
Joined: Mon Aug 11, 2008 9:09 pm

### Re: 11586 - Train Tracks

hi "aliahmed" your code not only TLE this is also Wrong methode.
read the problem again and try to find proper solution.
thanks

saiful_sust
Learning poster
Posts: 97
Joined: Fri Aug 22, 2008 10:18 pm
Location: CSE.SUST.SYLHET

### Re: 11586 - Train Tracks

u can do it with simple dp.....

read the problem carefully and solve it....

Taman
New poster
Posts: 32
Joined: Sun Oct 11, 2009 8:59 pm
Location: Southeast University

### Re: 11586 - Train Tracks

@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".

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 11586 - Train Tracks

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``````
Check input and AC output for over 7,500 problems on uDebug!

Experienced poster
Posts: 122
Joined: Tue Apr 16, 2002 10:07 am

### Re: 11586 - Train Tracks

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.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 11586 - Train Tracks

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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Experienced poster
Posts: 122
Joined: Tue Apr 16, 2002 10:07 am

### Re: 11586 - Train Tracks

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?

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 11586 - Train Tracks

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.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

arorag2396
New poster
Posts: 1
Joined: Wed Jan 27, 2016 5:13 am

### Re: 11586 - Train Tracks

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");

}

}

}