## 402 - M*A*S*H

Moderator: Board moderators

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:
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:
I exposed my poor English

mido
Learning poster
Posts: 78
Joined: Sun Jun 16, 2002 9:48 pm
Location: Cairo,Egypt
left=remaining
right=correct

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

### 402 WA

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);
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

Why do you open a third thread on 402?

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.

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
Thank you!
And sorry for the third thread on 402

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

### Larger X

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

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:
As I remembered, there's a post in the past about problem 402 (It's created by me ) 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
Contact:

### WA Still

My programs response:
I don't understand the problem. Can anyone help me?
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:
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:
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
Contact:

### What to do then

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:
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
Contact:
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:
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
Contact: