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

Rein
New poster
Posts: 5
Joined: Sun Jul 28, 2002 11:39 am

161 keep wa...

Post by Rein » Sun Jul 28, 2002 11:44 am

I really have touble with this prob...
I don't know why I keep getting WA :(

[c]/* @JUDGE_ID: 8789ec 161 C */
#include<stdio.h>
#include<string.h>

int lights[128],lights2[128];
char buff[128];

void main(){
int i,count,now;
char *k;k=strtok(buff," ");
while(1){

for(count=0,i=0;count<101;++count){
k=strtok(NULL," ");
while(k==NULL){
gets(buff);
if(strcmp(buff,"0 0 0")==0) return;
for(k=buff;*k!=NULL;++k)
if(*k=='\t')*k=' ';
k=strtok(buff," ");
}
lights[count]=atoi(k);
if(lights[count]==0)break;
if(lights[count]<10||lights[count]>90){--count;continue;}
if(lights[count]>i)i=lights[count];
lights2[count]=lights[count]*2;
}
if(count<2) continue;

now=i;
for(i=0;now<=300;++i){
if(now%lights2>=lights-5){
now+=(lights2-now%lights2);
i=-1;
continue;
}
if(i==count-1) break;
}
if(now>300) printf("Signals fail to synchronise in 5 hours\n");
else printf("00:%02d:%02d\n",now/60,now%60);
}
}


[/c]

visser
New poster
Posts: 8
Joined: Mon Jun 10, 2002 11:13 am
Location: Netherlands

Post by visser » Wed Jul 31, 2002 1:03 pm

1. 300 seconds is not 5 hours, but 5 minutes

2. At the end of your program you never print hours only lots of minutes!!
see: printf("00:%02d:%02d\n",now/60,now%60);

Rein
New poster
Posts: 5
Joined: Sun Jul 28, 2002 11:39 am

Post by Rein » Sat Aug 03, 2002 1:39 pm

I'm so sorry... :oops:
It seems that I asked a stupid question again...
but...I chganged the two places you mentioned...

I still got WA...

WillSent
New poster
Posts: 4
Joined: Fri Jan 17, 2003 1:26 pm

P161 - Traffic Lights - Test Data

Post by WillSent » Fri Jan 17, 2003 1:32 pm

Does anyone have some sample input and output for P161 - Traffic Lights that would really test my program? I keep getting WA and can't figure out why.

yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho » Sat Jan 18, 2003 2:30 am

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


Tell me how it goes, please.

WillSent
New poster
Posts: 4
Joined: Fri Jan 17, 2003 1:26 pm

Thanks, but need more

Post by WillSent » Sat Jan 18, 2003 11:09 am

Thanks for the test data. My program got the same output as your output. Do you have any more challenging input and output?

yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho » Sat Jan 18, 2003 6:08 pm

How about you give me some input data and I give you the output?

WillSent
New poster
Posts: 4
Joined: Fri Jan 17, 2003 1:26 pm

SOme More Input and Output

Post by WillSent » Sun Jan 19, 2003 9:04 pm

Here is some input with my output. Good Luck.

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

yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho » Sun Jan 19, 2003 11:54 pm

I also get the same result,

post your code and we'll debug from there

WillSent
New poster
Posts: 4
Joined: Fri Jan 17, 2003 1:26 pm

Thanks

Post by WillSent » Sat Jan 25, 2003 4:13 am

Thanks for all of your assistance. It was finally accepted.

Derk
New poster
Posts: 23
Joined: Mon Mar 17, 2003 3:53 am
Location: Louisville, KY
Contact:

161 WA - Need some inputs

Post by Derk » Thu Mar 27, 2003 1:52 pm

I get WA for this problem, but the test inputs work fine, as well as ones I come up with on my own. Does anyone have some thorough test inputs they used that worked with their program, and corresponding outputs?

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok » Fri Mar 28, 2003 6:04 am

I don't see any trick on this problem ... just do a straight simulation and got AC.

Rein, ... the input mentioned that a line with 3 zeroes terminates the input-file, however, it doesn't really specifically say that it is "0 0 0" like the one that you compared with. Could that be the problem ???

One more thing, don't you think it's easier to parse the input just using a loop of scanf() ??? I didn't see the need to use strtok() ...

Derk, ... I didn't see any trick on the input, ... the only thing is probably to test with a case that has solution in exactly 5 hours.

-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).

Derk
New poster
Posts: 23
Joined: Mon Mar 17, 2003 3:53 am
Location: Louisville, KY
Contact:

Thanks

Post by Derk » Fri Mar 28, 2003 10:06 am

That's exactly it! I changed my second counter to 18001 seconds and everything worked fine!

anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam » Thu Oct 30, 2003 8:45 pm

start with the minm of the input not the maxm.
i got wa when started with maxm. and check with a for loop for termination of input. :wink:
"Everything should be made simple, but not always simpler"

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

161 - Traffic Lights

Post by soyoja » Mon Mar 08, 2004 7:26 am

I don't know why I got WA...

Some of my testt case accepted by my solution. But OJ judged my
solution was wrong... Plz help me -_-

=============================================

[cpp]

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

using namespace std;

int main()
{
char light[101][18001];
int a, b, c, dat[101], cnt = 0, key, ans, hour, min, cycle = INT_MAX;

while(1)
{
for( a = 0; a < 101; a++ )
for( b = 0; b < 18001; b++ )
light[a] = '0';

cnt = ans = key = 0;
cin >> dat[cnt];

if( dat[cnt] != 0 )
{
while( 1 )
{
if( dat[cnt] == 0 ) break;
cnt++;
cin >> dat[cnt];
if( dat[cnt] < cycle ) cycle = dat[cnt];
}

// implementation
for( a = 0; a < cnt; a++ )
for( b = 0; b < 18001; b += (dat[a]*2) )
for( c = b; c < b + dat[a] - 5 && c < 18001; c++ ) light[a][c] = '1';


for( b = (cycle*2); b < 18001; b ++ )
{
key = 1;
for( c = 0; c < cnt; c++ )
{
if( light[c] != '1' )
{
key = 0;
break;
}
}
if( key )
{
ans = b;
break;
}
}

if( ans > 18000 || ans <= 0 )
printf( "Signals fail to synchronise in 5 hours\n" );
else // second translate to min, hour
{
hour = ans/3600, ans = ans%3600;
min = ans/60, ans = ans%60;
printf( "%02d:%02d:%02d\n", hour, min, ans );
}
}
else
{
cin >> dat[1] >> dat[2];
cnt = 2;
if( dat[1] == 0 && dat[2] == 0 )
break;
}
}

return 0;
}
[/cpp]

Post Reply

Return to “Volume 1 (100-199)”