Page 4 of 4

402 WA!!

Posted: Wed Sep 22, 2004 3:19 am
by midra
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...

I got PE in 402

Posted: Tue Sep 27, 2005 4:06 pm
by dreamvan
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 !!

402 - Somebody can explain it

Posted: Tue Aug 08, 2006 6:02 pm
by fcsc
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

Posted: Mon Oct 23, 2006 6:00 am
by jjtse
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.

Posted: Mon Oct 23, 2006 10:17 am
by sunny
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.

Posted: Mon Oct 23, 2006 8:15 pm
by jjtse
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.

Posted: Sat Dec 16, 2006 1:08 pm
by a123123123888
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.

Re: 402 help~

Posted: Wed Jul 30, 2008 7:52 pm
by yangmie
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;
}



Re: 402 - M*A*S*H

Posted: Tue Oct 28, 2014 2:01 am
by fabikw
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

Re: 402 - M*A*S*H

Posted: Tue Dec 23, 2014 1:45 pm
by lighted
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.

Re: 402 - M*A*S*H

Posted: Mon Jul 18, 2016 5:23 am
by metaphysis
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.

Re: 402 - M*A*S*H

Posted: Sat May 13, 2017 8:00 am
by uDebug
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