402 - M*A*S*H

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

Moderator: Board moderators

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann » Mon Jun 24, 2002 7:12 am

mido: yes

10153EN: "left" as in "left out" and "right?" like in "am I right?"

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN » Mon Jun 24, 2002 7:25 am

:D :D :D I exposed my poor English :D :D :D

mido
Learning poster
Posts: 78
Joined: Sun Jun 16, 2002 9:48 pm
Location: Cairo,Egypt

Post by mido » Mon Jun 24, 2002 2:49 pm

left=remaining
right=correct

Revenger
Experienced poster
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia

402 WA

Post by Revenger » Thu Jul 04, 2002 12:46 pm

Can anyone tell me why my program gets WA?

[pascal]Program p402;

Const MaxN = 100;

Var Inf,Card : Array[1..MaxN]of Integer;
N,X,i,j : Integer;
T,left,k : Integer;

begin
T:=0;
While Not Eof(InPut) Do begin
T:=T+1;
if T>1 then Writeln;
Writeln('Selection #',T);
Read(N,X);
for i:=1 to 20 do Read(Card);
left:=N;
for i:=1 to N do Inf:=0;
for i:=1 to 20 do begin
if left<=X then Break;
k:=0;
for j:=1 to N do begin
if Inf[j]=0 then begin
k:=k+1;
if k mod Card=0 then begin
Inf[j]:=1;
left:=left-1;
if left<=X then Break;
end;
end;
end;
end;
for i:=1 to N do
if Inf=0 then
Write(i,' ');
Writeln;
end;
end.[/pascal]

xenon
Learning poster
Posts: 100
Joined: Fri May 24, 2002 10:35 am
Location: Scheveningen, Holland

read previous mailing

Post by xenon » Thu Jul 04, 2002 3:20 pm

Why do you open a third thread on 402?
If you had read the previous threads, you could have found the answer.

One additional note:
you don't read line-breaks, so if there is a line-break after the last line in the inputfile, your program won't be able to detect the eof.

Another additional note:
The list of ``lucky" positions is then followed by a blank line.

Revenger
Experienced poster
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia

Post by Revenger » Thu Jul 04, 2002 5:13 pm

Thank you!
And sorry for the third thread on 402 :oops:

manir
New poster
Posts: 8
Joined: Sat Jul 06, 2002 7:14 am
Location: Bangladesh
Contact:

Larger X

Post by manir » Sat Jul 06, 2002 7:22 am

:o What is about larger X when we have finished our cards :o
The 2nd laziest person of the world

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN » Sat Jul 06, 2002 8:33 am

As I remembered, there's a post in the past about problem 402 (It's created by me :D ) and it's taking about this. You can have a look at it~

manir
New poster
Posts: 8
Joined: Sat Jul 06, 2002 7:14 am
Location: Bangladesh
Contact:

WA Still

Post by manir » Sat Jul 06, 2002 11:22 am

My programs response: :o
I don't understand the problem. Can anyone help me? :o
Input: :-?
10 2 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4
47 6 11 2 7 3 4 8 5 10 7 8 3 7 4 2 3 9 10 2 5 3
31 9 5 8 2 1 7 7 11 3 6 5 4 9 10 5 2 1 5 3 9 7
16 3 11 2 7 3 4 8 5 10 7 8 3 7 4 2 3 9 10 2 5 3
25 1 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11
10 11 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4
3 2 3
10 11 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4



Output: :cry:
Selection #1
1 8

Selection #2
1 3 16 23 31 47

Selection #3
6 8 12 14 17 21 23 26 28

Selection #4
1 3 16

Selection #5
1 2 3 4 5 6 11 19

Selection #6
1 2 3 4 5 6 7 8 9 10

Selection #7
1 2

Selection #8
1 2 3 4 5 6 7 8 9 10
The 2nd laziest person of the world

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN » Sat Jul 06, 2002 11:47 am

The outputs for me is the same as yours, except the third last and the last case.

In these two cases, i think it should not appear in the judge's data, as the number of lucky people is <= the total number of participant, as stated in the input description.

manir
New poster
Posts: 8
Joined: Sat Jul 06, 2002 7:14 am
Location: Bangladesh
Contact:

What to do then

Post by manir » Sat Jul 06, 2002 12:38 pm

But if the Judge Input is ok my program should work.

[c]
/*@begin_of_source_code*/
/* @JUDGE_ID: 13965AB 402 C*/
#include<stdio.h>
int people[51], remain, total, stop;
void init(){
for(int x=0;x<50;x++)
people[x]=1;
remain=0;total=0;
stop=0;
}
void main(){
int n,x,cur,f, count,c=0, space=0, cont;

#ifndef ONLINE_JUDGE
freopen("c:\\tcwin\\bin\\402.in","rt",stdin);
freopen("c:\\tcwin\\bin\\402.out","wt",stdout);

#endif

while(scanf("%d%d",&n,&x)==2){
if(c>0) printf("\n\n");
init();
if(x>n || n<=0 || x==0){
c++;
printf("Selection #%d\n",c);
space=0;
for(f=0;f<n;f++){
if(space) printf(" ");
printf("%d",f+1);
space++;
}
}
else{
total=n; stop=x; remain=n;
cont=0;
while(remain>stop){
if(cont>=20) break;
scanf("%d",&cur);
cont++;
count=0;
for(f=0;f<total;f++){
if(people[f]) count++;
if (count==cur){
if(remain<=stop) break;
people[f]=0;
remain--;
count=0;
}
}
}
c++;
printf("Selection #%d\n",c);
space=0;
for(f=0;f<total;f++)
if(people[f]){
if(space>0)printf(" ");
printf("%d",f+1);
space++;
}
}
char *st;
scanf("%[^\n]%c",st);
}
}

/*@end_of_source_code*/
[/c]
Last edited by manir on Sun Jul 14, 2002 2:03 am, edited 1 time in total.
The 2nd laziest person of the world

Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post by Picard » Sat Jul 06, 2002 1:44 pm

the problem is:

Code: Select all

char *st; 
scanf("%[^\n]%c",st);
1. you pass an unassigned char* pointer for %[^\n]
2. you don't pass parameter for %c

manir
New poster
Posts: 8
Joined: Sat Jul 06, 2002 7:14 am
Location: Bangladesh
Contact:

Post by manir » Sat Jul 06, 2002 3:43 pm

Thanks.
But I still get a nice WA.
Last edited by manir on Sun Jul 14, 2002 2:16 am, edited 1 time in total.
The 2nd laziest person of the world

Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post by Picard » Sat Jul 06, 2002 4:28 pm

how did you correct it? i replaced the mentioned two lines with 'while (getchar()!=10);' and it got PE (but not WA).

manir
New poster
Posts: 8
Joined: Sat Jul 06, 2002 7:14 am
Location: Bangladesh
Contact:

Post by manir » Sat Jul 06, 2002 5:06 pm

:) :)
Thanks for your help.
This show no problem while I test in my computer. Probably the word processor I am using is making the problem.
I waste a whole day to solve this.
:P :P
The 2nd laziest person of the world

Post Reply

Return to “Volume 4 (400-499)”