11586 - Train Tracks

All about problems in Volume 115. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

11586 - Train Tracks

Post by shiplu_1320 » Tue Mar 03, 2009 11:31 pm

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

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

Re: 11586 - Train Tracks

Post by sohel » Wed Mar 04, 2009 8:00 am

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

Post by shiplu_1320 » Wed Mar 04, 2009 12:07 pm

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

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

Re: 11586 - Train Tracks

Post by sohel » Wed Mar 04, 2009 2:59 pm

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

Post by shiplu_1320 » Wed Mar 04, 2009 3:17 pm

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

aliahmed
New poster
Posts: 24
Joined: Fri Oct 24, 2008 8:37 pm
Location: CUET, Chittagong, Bangladesh
Contact:

Re: 11586 - Train Tracks

Post by aliahmed » Fri Apr 03, 2009 1:48 am

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

Post by MRH » Fri Apr 03, 2009 6:13 am

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

Post by saiful_sust » Sat Sep 05, 2009 6:40 pm

u can do it with simple dp.....
or easy adhoc...........

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

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

Re: 11586 - Train Tracks

Post by Taman » Thu May 27, 2010 5:19 pm

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

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

Re: 11586 - Train Tracks

Post by uDebug » Mon Dec 23, 2013 9:49 am

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!

Find us on Facebook. Follow us on Twitter.

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

Re: 11586 - Train Tracks

Post by Zyaad Jaunnoo » Mon Aug 11, 2014 6:21 pm

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

Post by lighted » Wed Dec 24, 2014 5:41 pm

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

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

Re: 11586 - Train Tracks

Post by Zyaad Jaunnoo » Sat Dec 27, 2014 11:38 pm

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

Post by lighted » Tue Dec 30, 2014 9:18 am

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

Post by arorag2396 » Wed Jan 27, 2016 5:21 am

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





}

}

}

Post Reply

Return to “Volume 115 (11500-11599)”