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

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Mon Jul 15, 2002 12:21 pm

In problem description says:
The next 20 integers are the values of the first 20 cards in the deck.
But that not true .... integers may be less ....

NONAME_SUST
New poster
Posts: 8
Joined: Tue Jul 23, 2002 9:15 am

GIVE SOME TEST INPUT FOR 402

Post by NONAME_SUST » Wed Jul 24, 2002 3:50 pm

Hi,
I have a problem with 402. I have tried with example input and output an got the exact result. Can anyone give me some input and output..
HEY WANT TO GET SOL.TRY ON http://www.uvexam.zzn.com from 1st September

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Wed Jul 24, 2002 5:26 pm

I (and maybe more persons) have a request for you:
try to read messages on this board before you start new thread .... examples, which you are looking for, are in one of threads below ....

nice reading :-))

NONAME_SUST
New poster
Posts: 8
Joined: Tue Jul 23, 2002 9:15 am

YOU ARE TOO SHORT

Post by NONAME_SUST » Mon Jul 29, 2002 8:44 am

Hi,
what y write on ur header r too short. So..try to make the header bigger as anyone can understand. Moreover..Thanks for ur wrong answer..So resubbmit ur problem with 20 minutes penalty...
HEY WANT TO GET SOL.TRY ON http://www.uvexam.zzn.com from 1st September

Shahid
Learning poster
Posts: 68
Joined: Fri Oct 26, 2001 2:00 am
Location: Dhaka, Bangladesh
Contact:

i solved it, but can't get out of the presentation error

Post by Shahid » Tue Aug 20, 2002 2:48 am

hi, can nayone help me to out of theis presentaion error, i tried several times but all failed...her is my code :

[c]


/*@BEGIN_OF_SOURCE_CODE*/



#include<stdio.h>

void main()
{
int lot, luc, deck[20], man[51], i, j, p, rest, bad, count = 0;

while(1)
{
if(count)
printf("\n");

i = scanf("%d", &lot);
if(i != 1)
break;

scanf("%d", &luc);
j = 0;
rest = 0;
bad = lot - luc;
for(i = 0; i < 20; i++)
scanf("%d", &deck);

for(i = 0; i < lot; i++)
man = 1;

count++;

for(i = 0; i < 20; i++)
{
if(rest == bad)
break;

for(;;)
{
for(p = 0; p < deck; j++ )
if(man[j])
p++;

j--;

if(j > (lot - 1))
{
j = 0;
break;
}

else
{
man[j] = 0;
rest++;
if(rest == bad)
break;
}
}
}
printf("Selection #%d\n", count);

for(i = 0; i < lot; i++)
if(man)
printf("%d ", i+1);
}
}

/*@END_OF_SOURCE_CODE*/

[/c]


thanx in advance

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Wed Aug 21, 2002 10:53 am

imagine that & is space :-)
I think that your solution output something like this

Selection&#1
1&2&

I think, that after last digit should not be a space

try

printf("<first number>");
for(...) printf("<space><another number>);

:-)

Shahid
Learning poster
Posts: 68
Joined: Fri Oct 26, 2001 2:00 am
Location: Dhaka, Bangladesh
Contact:

i changed, but no change in judge reply....

Post by Shahid » Fri Aug 30, 2002 11:18 pm

hi , i changed as u said...but no way...judge says P.E. again.....whats the problem? here is the changed code:


[cpp] /*@BEGIN_OF_SOURCE_CODE*/


#include<stdio.h>

void main()
{
int lot, luc, deck[25], man[55], i, j, p, rest, bad, count = 0;

while(1)
{
i = scanf("%d", &lot);
if(i != 1)
break;

scanf("%d", &luc);
j = 0;
rest = 0;
bad = lot - luc;

for(i = 0; i < 20; i++)
scanf("%d", &deck);

for(i = 0; i < lot; i++)
man = 1;

if(count)
printf("\n");

count++;
for(i = 0; i < 20; i++)
{
if(rest == bad)
break;

for(;;)
{
for(p = 0; p < deck; j++ )
if(man[j])
p++;
j--;
if(j > (lot - 1))
{
j = 0;
break;
}

else
{
man[j] = 0;
rest++;
if(rest == bad)
break;
}
}
}
printf("Selection #%d\n", count);

for(i = 0; i < lot; i++)
if(man)
{
printf("%d", i+1);
break;
}
i++;
for(; i < lot; i++)
if(man)
printf(" %d", i+1);
printf("\n");
}
}

/*@END_OF_SOURCE_CODE*/
[/cpp]

supermin
New poster
Posts: 37
Joined: Sat Oct 12, 2002 9:54 am
Location: (Taiwan)
Contact:

Post by supermin » Mon Dec 02, 2002 12:46 pm

Adrian Kuegel wrote:Your output is correct, but test your program with this input (I am not sure that it is used, but I considered the case in my program):
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 2 3 4 5 6 7 8 9 10
I ignore this sample,but I still got Acceptd..
I thougth the judge dosen't have this case.

User avatar
hank
Experienced poster
Posts: 146
Joined: Mon Feb 04, 2002 2:00 am
Location: VCORE.

402 M*A*S*H wrong answer

Post by hank » Sun Dec 08, 2002 3:11 pm

:oops: Why I got WA?
here is my source.

help me! ^_^
[c]
/* @JUDGE_ID:17511FE 402 C */
/* A */
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
int card[1000];
int people[51];
void main()
{
int N,M;
int i,j,k,count,this_card,rest,temp;
int times=0;
char arr[1000],*p;
while( gets(arr) ){
/*input*/
p=strtok(arr," ");
N=atoi(p);
p=strtok(NULL," ");
M=atoi(p);
for(i=1;i<1000;i++){
p=strtok(NULL," ");
if(p==NULL) break;
card=atoi(p);
}
/**initial**/
for(i=1;i<=N;i++)
people=i;
this_card=1;
rest=N;
/**START**/
do{
for(i=1,count=0;i<=N&&rest>M;i++){
if(people!=-1)
count++;
if(count==card[this_card]){
people=-1;
count=0;
rest--;
}
}/*for*/
this_card++;
}while(rest>M);
/****/
printf("Selection #%d\n",++times);
for(i=1,k=0;i<=N;i++){
if(people!=-1){
if(k>0) putchar(' ');
printf("%d",i);
k++;
}
}
printf("\n\n");
}
}
[/c]

cym
New poster
Posts: 15
Joined: Mon Oct 14, 2002 3:45 pm
Contact:

Post by cym » Fri Dec 20, 2002 5:08 pm

You can see here for some tips 8)
http://acm.uva.es/board/viewtopic.php?t=121

User avatar
SeaViperz
New poster
Posts: 4
Joined: Mon Dec 30, 2002 9:44 am

Why?

Post by SeaViperz » Wed Apr 09, 2003 5:16 pm

sjn:
who can tell me what is the output for
25 1 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11
Adrian Kuegel:
Output is:
Selection #1
1 2 3 4 5 6 11 19
Can someone please explain why this should happen?
*****SeaViperz*****
Draw your fangs and let's duel.
For my poison serves forever as my fuel!

Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong

Post by Eric » Wed Apr 09, 2003 5:29 pm

This is because after the 20 numbers have been "executed", this number still remain unchanged.
There is a test case that the number of card is less than 20. Take care about it also.

InOutMoTo
New poster
Posts: 18
Joined: Sun Aug 10, 2003 12:47 pm

Re: WA Still

Post by InOutMoTo » Tue Sep 09, 2003 2:42 pm

manir wrote: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
This prob's special case is very much!
After many WAs , I got AC by handle out all special case above.

MUST BE CAREFUL that the conditions on Problem Set is not all matched!

Daredevil
New poster
Posts: 19
Joined: Tue Apr 01, 2003 7:47 am
Location: Earth

Why is 402 - M*A*S*H Runtime error (SISEGV)?

Post by Daredevil » Sun Oct 19, 2003 12:51 pm

[cpp]
#include<stdio.h>
#include<malloc.h>

struct person{
int n;
struct person*next;
}*head,*tail,*cur;

void build(int p){
head=tail=cur=0;
for(int i=0;i<p;i++){
cur=(struct person*)malloc(sizeof(struct person));
cur->n=i+1;
if(!head) head=cur;
else tail->next=cur;
tail=cur;
tail->next=0;
}
}

void main(){
int p,s,count=0,card[22],i,j,k;
while(scanf("%i %i",&p,&s)==2){
if(count) printf("\n");
count++;
for(i=0;i<20;i++) scanf("%i",&card);
printf("Selection #%i\n",count);
build(p);
for(i=0,s=p-s;i<20&&s;i++){
j=card-2;
if(j==-1){
while(s){
cur=head->next;
free(head);
head=cur;
s--;
}
}
else{
cur=head;
while(cur->next){
for(k=0;k<j&&cur->next;cur=cur->next,k++);
if(cur->next){
tail=cur->next;
cur->next=tail->next;
free(tail);
cur=cur->next;
s--;
if(!s) break;
}
}
}
}
printf("%i",head->n);
cur=head->next;
free(head);
while(cur){
printf(" %i",cur->n);
head=cur->next;
free(cur);
cur=head;
}
printf("\n");
}
}
[/cpp]
Thnx!!

User avatar
mlvahe
New poster
Posts: 23
Joined: Wed Jul 30, 2003 6:54 am
Location: Yerevan, Armenia

402 Why WA

Post by mlvahe » Sun Apr 11, 2004 10:53 am

Please help to find the bug in my program.

[cpp]
#include <iostream.h>

main()
{
int i, j, n, x, m, sld[51], cards[23], l, si;
bool b;
char c;
si = 1;
while (cin >> n >> x)
{
for (i = 1; i <= 50; i++)
sld = i;
i = -1;
b = false;
c = cin.get();
while (c != '\n')
{
if (('0'<=c) && (c <= '9'))
if (b)
cards = cards*10+c-'0';
else
cards[++i] = c - '0';
b = (('0'<=c) && (c <= '9'));
c = cin.get();
}
l = 0;
while (n > x)
{
m = cards[l++];
i = m;
while (n > x && i <= n)
{
for (j = i+1; j <= n; j++)
sld[j-1] = sld[j];
sld[n] = -1;
n--;
i += m-1;
}
}
cout << "Selection #" << si++ << "\n" << sld[1];
for (i = 2; i <= n; i++)
cout << " " << sld;
cout << "\n\n";
}
return 0;
}
[/cpp]
I'll be greatful if you told me a test case that my program doesn'e solve.

Post Reply

Return to “Volume 4 (400-499)”