161 - Traffic Lights

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

Moderator: Board moderators

junbin
Experienced poster
Posts: 174
Joined: Mon Dec 08, 2003 10:41 am

Post by junbin » Tue Mar 09, 2004 2:20 am

This is a fairly simple simulation question.. so I think your problem is probably a careless mistake.. try reading the question more carefullly... if you still need help, generate some test data and I'll post the results my program gives.

Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm

Post by Almost Human » Fri Mar 12, 2004 8:41 am

I'm stuck on this problem.

Can somebody show me the output for this :
0
0
0 0 0

thank you

El-idioto
New poster
Posts: 45
Joined: Mon Jul 14, 2003 9:42 pm
Location: Zoetermeer, The Netherlands

Post by El-idioto » Fri Mar 19, 2004 5:22 pm

Almost human,

There shouldn't be any output for your example.

Dejarik
New poster
Posts: 32
Joined: Sun Mar 07, 2004 1:23 pm
Location: Barcelona, SPAIN
Contact:

Post by Dejarik » Sun Mar 21, 2004 3:08 pm

Almost human, i've tried your input in my ACC problem and of course it does not output anything...

The common mistake of this problem is to let the algorithm manage the case where the total amount of time is exactly 5 hours. This case MUST be printed, and the message of "Fail to synchronise..." should only be printed when the total time is 5 hours 1 second or up...

Another common problem (but i'm sure you will have checked it) is printing the time: 00:00:50, and never 00:00:050, for seconds minutes or houres greater than 9 units.

This problem is not very difficult, if you want put here some inputs and outputs and i will let execute them also in my program.

Good luck!

Joan

jagadish
Learning poster
Posts: 90
Joined: Mon Feb 16, 2004 8:53 pm
Location: Bangalore INDIA

161 - sample input-output needed

Post by jagadish » Thu May 13, 2004 5:48 am

can anyone give me some sample input/output for this one..
this was the data set i tested it with..

19 20 0
30 25 35 0
11 13 17 12 14 35 34 33 99 0
10 15 20 30 25 35 75 74 13 11 0
10 11 12 13 14 15 16 17 18 19 20 34 56 66 100 0
10 11 12 13 14 0
6 6 6 6 6 6 8 8 8 0
6 8 0
101 106 102 89 34 56 89 65 12 90 54 78 98 23 12 45 21 26 78 0
101 103 105 107 109 113 117 121 89 33 31 122 13 34 35 91 0
19 20 25 30 35 45 13 55 65 75 85 15 0
0 0 0

output:

00:00:40
00:05:00
03:44:28
04:10:04
Signals fail to synchronise in 5 hours
00:25:40
00:00:48
00:00:48
Signals fail to synchronise in 5 hours
00:01:18
00:26:00

desperate to get AC
~ jagadish

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 » Sat May 15, 2004 3:12 pm

My AC program give the same output.

Did you handle the case where the time to be printed is exactly 5 hrs?

Here are some other test data I found in the forum:

input:
19 20 0
30
25 35 0
30 58 62 32 31 32 22 64 89 90
10 27 10 29 56 35 28
45 56 58
29 28 54 78 58 96 32 10 28 35
36 98 75 32 54 85 96
32 42 45
10 27 77 88 28 62 52 35 53 90
50 51 52 53 56 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77
78 79
80 81 82 83 84 85 86 87 88 89
90 31 32 33 34 35 36 37 38 41
0
10 10 0
11 10 12 13 14 0
10 11 12 13 14 15 16 17 18 19 20 0
10 26 0
42 87 88 90 0
53 54 55 68 20
0
50 51 52 53 54 55 56 25
18 0
56 90 10 25 32 64 58 52 0
0 0 0

ouput:
00:00:40
00:05:00
Signals fail to synchronise in 5 hours
00:00:20
00:25:40
Signals fail to synchronise in 5 hours
00:00:20
00:03:00
00:00:40
00:01:52
00:19:20

and

Input:
13 57 22
17 0
71 83 23 0
11 13 19 29 44
90 0
22 24 26 28 30 35 45 55 65 70 71
0
10 20 30 40 50 60 70 80 90 0
89 87 81 83 79 0
10 11 12 13 14 15 16 17 18 19 20 0
41 83 23 19 20 75
0
11 31 53 67 83 0
22 32 42 52 62 72 82 0
21 23 25 88 30 33 37 70 79 75
72 41 42 43 43 43 43 61 61 61 61 0
0 0 0


Output:
00:02:16
00:00:46
00:31:12
Signals fail to synchronise in 5 hours
00:24:00
00:02:58
Signals fail to synchronise in 5 hours
00:26:04
00:00:22
00:44:00
03:05:02

Hope this helps.

jagadish
Learning poster
Posts: 90
Joined: Mon Feb 16, 2004 8:53 pm
Location: Bangalore INDIA

Post by jagadish » Mon May 17, 2004 7:38 pm

thanx got AC now :D .. was not checking for a boundary condition before

Andrew_PL
New poster
Posts: 34
Joined: Fri Sep 02, 2005 12:08 pm
Location: Poland

161 Traffic Lights

Post by Andrew_PL » Fri Sep 02, 2005 12:22 pm

Hi All
I have a problem with 161. I'm getting WA all the time. I found it a simple problem, thought. Even old posts on forum didn't help me. Of course my program works fine with simple input, and it works for "9000 0" (shows "05:00:00").

Can someone tell me where I'm making mistake?

Code: Select all

#include "stdio.h"
int main()
{
	int sig[101]; // input, cycle time
	const int mt=5*60*60+1; // max time
	int green[mt]; // how many signals are green
	int count, i;
	
	for (;;)
	{
		// read input
		for (count=0;; count++)	{
			scanf("%d", &sig[count]);
			if (sig[count] == 0) break;
		}
		if (sig[0] == 0) break; // exit condition

		for (i=0; i < mt; i++) green[i] = 0;
		
		for (i=0; i < count; i++) // for every signal
		{
			for (int k=0; k < mt; k+=sig[i]*2) // for every cycle
			{
				for (int m=0; m < sig[i]-5; m++) // mark when it's green
					if (k+m < mt) green[k+m] += 1;
			}
		}

		// check when all signals were green
		for (i=sig[0]+1; i < mt; i++) 
		{
			if (green[i]==count) break;
		}
		if (i == mt) printf("Signals fail to synchronise in 5 hours\n");
		else {
			int g = i/3600;
			int m = (i-g*3600)/60;
			int s = i-g*3600-m*60;
			printf("0%d:", g);
			if (m < 10) printf("0");
			printf("%d:", m);
			if (s < 10) printf("0");
			printf("%d\n", s);
		}
	}// for (;;)

	scanf("%d", &sig[0]); // read following zeros
	scanf("%d", &sig[0]);
	return 0;
}

Andrew_PL
New poster
Posts: 34
Joined: Fri Sep 02, 2005 12:08 pm
Location: Poland

Post by Andrew_PL » Fri Sep 02, 2005 8:55 pm

I don't know how it happened, but when I accidentally posted the code from post above I've got AC :-\ But before I've got WA two times!

MEGADEEN
New poster
Posts: 5
Joined: Sun Jun 15, 2014 9:26 am

Re: P161 - Traffic Lights - Test Data

Post by MEGADEEN » Sat Jun 28, 2014 12:44 pm

I tested my program with the test cases mentioned previously and mine seem to be correct but I keep on getting WA. Can someone please help me?

Code: Select all

My code got accepted.
Last edited by MEGADEEN on Sun Jun 29, 2014 8:55 am, edited 1 time in total.

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: P161 - Traffic Lights - Test Data

Post by lbv » Sat Jun 28, 2014 9:05 pm

MEGADEEN wrote:I tested my program with the test cases mentioned previously and mine seem to be correct but I keep on getting WA. Can someone please help me?
Try:

Input

Code: Select all

68 36 31 69 67 62 35 35 43 37 30 0
0 0 0
Output

Code: Select all

05:00:00

MEGADEEN
New poster
Posts: 5
Joined: Sun Jun 15, 2014 9:26 am

Re: P161 - Traffic Lights - Test Data

Post by MEGADEEN » Sun Jun 29, 2014 8:54 am

lbv wrote:
MEGADEEN wrote:I tested my program with the test cases mentioned previously and mine seem to be correct but I keep on getting WA. Can someone please help me?
Try:

Input

Code: Select all

68 36 31 69 67 62 35 35 43 37 30 0
0 0 0
Output

Code: Select all

05:00:00
Thank you! That solved the problem.

dibery
Learning poster
Posts: 76
Joined: Sat Feb 23, 2013 4:16 pm
Location: Taiwan, Taipei
Contact:

Re: 161 - Traffic Lights

Post by dibery » Tue Aug 12, 2014 8:08 am

Hi, I have a problem.

The following code got TLE

Code: Select all

int main()
{
	int time[ 100 ], in, size = 0, M = 100, ans = 0;

	while( scanf( "%d", &in ) != EOF )
		if( in )
			time[ size++ ] = in, M = std::min( M, in );
		else if( size )
		{
			//do something
		}
}
But this one got AC:

Code: Select all

int main()
{
	int time[ 100 ], in, size = 0, M = 100, ans = 0;

	while( scanf( "%d", &in ) == 1 )
		if( in )
			time[ size++ ] = in, M = std::min( M, in );
		else if( size )
		{
			//do the same thing as above
		}
}
Why EOF doesn't work?
Life shouldn't be null.

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 161 - Traffic Lights

Post by lbv » Tue Aug 12, 2014 9:34 am

dibery wrote:Hi, I have a problem.

The following code got TLE(..)
But this one got AC: (..)
Why EOF doesn't work?
The judge's data probably has some strange characters at the end of the file, which is something not too uncommon in UVa's archives.

It seems like the most likely scenario is that at some point scanf finds data to read, but it's not an int, so it returns zero, and it gets stuck trying to read the same piece of strange data over and over (and returning zero every time).

There was a similar question recently where you can find a little more detailed explanation: http://acm.uva.es/board/viewtopic.php?f ... 45#p370609

Post Reply

Return to “Volume 1 (100-199)”