11586 - Train Tracks
Moderator: Board moderators
-
- 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....
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......
Re: 11586 - Train Tracks
There is no counterexample!
What you said is correct.
What you said is correct.
-
- 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......
Re: 11586 - Train Tracks
pieces=0; should be inside the while() loop, shouldn't it?
-
- New poster
- Posts: 32
- Joined: Sat Dec 29, 2007 9:08 pm
- Location: CSEDU , Dhaka
- Contact:
-
- New poster
- Posts: 24
- Joined: Fri Oct 24, 2008 8:37 pm
- Location: CUET, Chittagong, Bangladesh
- 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..
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.
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
read the problem again and try to find proper solution.
thanks
-
- 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.....
or easy adhoc...........
read the problem carefully and solve it....![]()
Re: 11586 - Train Tracks
@Aliahmed:
Well then consider the case,You can do it simply by counting male & female conector.
if male conector equals to female conector then LOOP other wise NO LOOP
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".1
MF FM
Re: 11586 - Train Tracks
I found these test cases useful during my testing / debugging for this problem.
Input:
AC Output:
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
Code: Select all
LOOP
LOOP
LOOP
NO LOOP
LOOP
LOOP
NO LOOP
NO LOOP
-
- Experienced poster
- Posts: 122
- Joined: Tue Apr 16, 2002 10:07 am
Re: 11586 - Train Tracks
Just to make your statement more robust, consider the case where you have the only 2 pieces: MF FM.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....
Here, no. of MM = no. of FF = 0.
However, in such case, there is no loop.
Re: 11586 - Train Tracks
Zyaad Jaunnoo wrote:Just to make your statement more robust, consider the case where you have the only 2 pieces: MF FM.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....
Here, no. of MM = no. of FF = 0.
However, in such case, there is no loop.
Code: Select all
1
MF FM
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
Indeed strange. However, logically we should not be able to make a loop.lighted wrote:My accepted code returns "LOOP" for this case (same as uDebug and uvatoolkit)Code: Select all
1 MF FM
Am I correct?
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
-
- 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");
}
}
}
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");
}
}
}