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

midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

402 WA!!

Post by midra » Wed Sep 22, 2004 3:19 am

I can't figure out what's wrong with my code
I have test all the samples input/output that I found in this forum and they work ok.
please, if someone knows I would appreciate very much that tells me some possible tricky case or something like that.
thanks!!!

Here is my code:
[c]
#include <stdio.h>

int card[21];
int cases=0;

int evaluate(int n, int x){
int i,j;
int people[50];
int n2,temp=0;
int index=0;
n2=n;
for (i=1;i<=n;i++)
people=1;
while(n2>x){
index++;
if (index>20){
printf("Selection #%d\n",cases);
for (i=1;i<=n;i++)
if (people==1) printf("%d ",i);
printf("\n\n");
return 0;
}
for (i=1,temp=1;i<=n;i++){
if (temp==card[index]){
if (people==1){
people=0;
n2--;
if (n2==x) goto a;
}
else if (people==0)
while(i<=n){
i++;
if (people==1){
people=0;
n2--;
if (n2==x) goto a;
break;
}
}
temp=1;
}
else{
if (people==1) temp++;
}

}
}
a:
printf("Selection #%d\n",cases);
for (i=1;i<=n;i++)
if (people==1) printf("%d ",i);
printf("\n\n");
}



int main()
{
int n; /*people participating in the lottery*/
int x; /*how many lucky positions*/
int i;
while(scanf("%d %d",&n,&x)!=EOF){
cases++;
for (i=1;i<=20;i++)
scanf("%d",&card);
evaluate(n,x);
}
return 0;
}[/c]

I know it's an ugly code ...but I am a beginner...

dreamvan
New poster
Posts: 2
Joined: Sat Sep 24, 2005 10:56 am

I got PE in 402

Post by dreamvan » Tue Sep 27, 2005 4:06 pm

I got PE in 402........

Code: Select all

#include <stdio.h>

int array[50];

int main()
{
	int total,remain,i,num,count,j,s=1;

	while(scanf("%d",&total)==1)
	{
		scanf("%d",&remain);
		for(i=0;i<20;i++)
		{
			scanf("%d",&num);
			count=0;
			for(j=0;j<total;j++)
			{
				if(total==remain) break;
				if(array[j]==0) 
				{
					count++;
					if(count==num)
					{
						array[j]=1;
						remain++;
						count=0;
					}
				}
			}
		}
		printf("Selection #%d\n",s);
		s++;
		for(i=0;i<total;i++)
		{
			if(array[i]==0) printf("%d ",i+1);
			else array[i]=0;
		}		
		printf("\n\n");
	}

	return 0;
}

Can someone help me !! Thanks a lot !!

fcsc
New poster
Posts: 3
Joined: Wed Mar 01, 2006 4:33 pm

402 - Somebody can explain it

Post by fcsc » Tue Aug 08, 2006 6:02 pm

I am reading the M.A.S.H problem and i cannot understand the first example, when they said we have 10 people. 2 of them will be lucky and cards 3, 5, 4, 3, 2

these is the line: 1 2 3 4 5 6 7 8 9 10

1rst card:
1 2 X 4 5 6 7 8 9 10
2n card:
1 2 X 4 5 X 7 8 9 10
3d card:
1 2 X 4 X X 7 8 9 10
4th card:
1 2 X X X X 7 8 9 10
5th card:
1 X X X X X 7 8 9 10

if we only have these cards the result should be 1 - 7, if we have all the cards yes will be 1 8 but i cannot understand the second example.

If somebody can help ...

PD: Sorry for my english
____________________________
"Free software for a free society"

jjtse
Learning poster
Posts: 80
Joined: Mon Aug 22, 2005 7:32 pm
Location: Nevada, US
Contact:

Post by jjtse » Mon Oct 23, 2006 6:00 am

Dominik Michniewski wrote: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 ....


Can someone verify this above statement? The problem specification says there will be "22" integers in a line. And that's what I'm assuming. If a line can have fewer than 22 numbers, then my program doesn't work.

Can someone confidently tell me that if my program assumes 22 integers in a line, then my program won't work?



Thanks.

sunny
Experienced poster
Posts: 124
Joined: Sun Sep 11, 2005 10:22 pm
Location: Civil-BUET

Post by sunny » Mon Oct 23, 2006 10:17 am

jjtse wrote:

Can someone verify this above statement? The problem specification says there will be "22" integers in a line. And that's what I'm assuming. If a line can have fewer than 22 numbers, then my program doesn't work.

Can someone confidently tell me that if my program assumes 22 integers in a line, then my program won't work?


there are always 22 integers in a line. u have some other bug.

jjtse
Learning poster
Posts: 80
Joined: Mon Aug 22, 2005 7:32 pm
Location: Nevada, US
Contact:

Post by jjtse » Mon Oct 23, 2006 8:15 pm

Thanks. I already fixed it. It was indeed some other bug. So for future reference, it is safe to assume exactly 22 integers in one input line.

a123123123888
New poster
Posts: 7
Joined: Fri Mar 31, 2006 1:22 pm

Post by a123123123888 » Sat Dec 16, 2006 1:08 pm

No. The problem is not like that.

For first example:

start:1 2 3 4 5 6 7 8 9 10

1st card:

1 2 . 4 5 6 7 8 9 10

1 2 . 4 5 . 7 8 9 10

1 2 . 4 5 . 7 8 . 10

2nd card:

1 2 . 4 5 . . 8 . 10

3rd card:

1 2 . 4 . . . 8 . 10

4th card:

1 2 . . . . . 8 . 10

5th card:

1 . . . . . . 8 . 10

1 . . . . . . 8 . .

so, the remaining people are 1 and 8.

yangmie
New poster
Posts: 3
Joined: Fri Nov 30, 2007 12:14 pm
Contact:

Re: 402 help~

Post by yangmie » Wed Jul 30, 2008 7:52 pm

why i got TLE ?
i try all the test cases i can find and pass it,but still TLE...

thx for your help...

Code: Select all

#include<stdio.h>
#include<stdlib.h>

typedef struct node{
        int no;
        struct node *next;
}NODE;

int main(){
        int n,x,y,live,tp,times=1;
        int kill[20];
        NODE *root;
        NODE *newptr;
        NODE *tmp;
        while(scanf("%d%d",&n,&live)){
                for(x=0;x<20;x++)scanf("%d",&kill[x]);

                root = (NODE*)malloc(sizeof(NODE));
                root -> no = 0;
                tmp = root;
                for(x=1;x<=n;x++){
                        newptr = (NODE*)malloc(sizeof(NODE));
                        newptr -> no = x;
                        tmp -> next = newptr;
                        tmp = tmp -> next;
                }
                tmp -> next = NULL;
                y=0;
                while(n>live&&y<20){
                        tmp = root;
                        tp = n;
                        while(tp >=kill[y]){
                                for(x=1;x<kill[y];x++)tmp = tmp -> next;
                                tmp ->next = tmp -> next ->next;
                                n--;
                                if(n<=live)break;
                                tp -= kill[y];
                        }
                        y++;
                }
                printf("Selection #%d\n",times++);
                root = root -> next;
                while(root -> next){
                        printf("%d ",root->no);
                        root = root -> next;
                }
                printf("%d\n",root->no);
                putchar('\n');
                free(root);
        }
        return 0;
}



fabikw
New poster
Posts: 3
Joined: Tue Oct 28, 2014 1:59 am

Re: 402 - M*A*S*H

Post by fabikw » Tue Oct 28, 2014 2:01 am

I cannot find the error in this code. I keep getting WA even though I can pass all test cases I've thought of. Can somebody give me a hand? Preferably by posting some test case that doesn't work.

Code: Select all

Accepted

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 402 - M*A*S*H

Post by lighted » Tue Dec 23, 2014 1:45 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
Input above is invalid. According to problem description there won't be case when X > N. There are always 22 integers in a line. Also as Adrian Kuegel posted to get accepted we should print all remaining people even if their number is > X.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

metaphysis
Experienced poster
Posts: 139
Joined: Wed May 18, 2011 3:04 pm

Re: 402 - M*A*S*H

Post by metaphysis » Mon Jul 18, 2016 5:23 am

The test data on uDebug:

Code: Select all

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
10 11 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4 is not valid, X <= N.
3 2 3 is not valid, every line contains 22 integer.
You need not to handle cases like this.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 402 - M*A*S*H

Post by uDebug » Sat May 13, 2017 8:00 am

metaphysis wrote:
Mon Jul 18, 2016 5:23 am
The test data on uDebug:

Code: Select all

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
10 11 3 5 4 3 2 9 6 10 10 6 2 7 3 4 7 4 5 3 2 4 is not valid, X <= N.
3 2 3 is not valid, every line contains 22 integer.
You need not to handle cases like this.
Thank you. This input has been deleted.

Also, for faulty input or other concerns, please feel free to reach out directly using one of the methods described here

https://www.udebug.com/faq#team-udebug-section
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 4 (400-499)”