Page 2 of 2
Posted: Tue Mar 09, 2004 2:20 am
by junbin
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.
Posted: Fri Mar 12, 2004 8:41 am
by Almost Human
I'm stuck on this problem.
Can somebody show me the output for this :
0
0
0 0 0
thank you
Posted: Fri Mar 19, 2004 5:22 pm
by El-idioto
Almost human,
There shouldn't be any output for your example.
Posted: Sun Mar 21, 2004 3:08 pm
by Dejarik
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
161 - sample input-output needed
Posted: Thu May 13, 2004 5:48 am
by jagadish
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
Posted: Sat May 15, 2004 3:12 pm
by chunyi81
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.
Posted: Mon May 17, 2004 7:38 pm
by jagadish
thanx got AC now

.. was not checking for a boundary condition before
161 Traffic Lights
Posted: Fri Sep 02, 2005 12:22 pm
by Andrew_PL
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;
}
Posted: Fri Sep 02, 2005 8:55 pm
by Andrew_PL
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!
Re: P161 - Traffic Lights - Test Data
Posted: Sat Jun 28, 2014 12:44 pm
by MEGADEEN
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?
Re: P161 - Traffic Lights - Test Data
Posted: Sat Jun 28, 2014 9:05 pm
by lbv
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
Re: P161 - Traffic Lights - Test Data
Posted: Sun Jun 29, 2014 8:54 am
by MEGADEEN
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
Thank you! That solved the problem.
Re: 161 - Traffic Lights
Posted: Tue Aug 12, 2014 8:08 am
by dibery
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?
Re: 161 - Traffic Lights
Posted: Tue Aug 12, 2014 9:34 am
by lbv
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