402 - M*A*S*H
Moderator: Board moderators
402 WA!!
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 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
I got PE in 402........
Can someone help me !! Thanks a lot !!
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;
}
402 - Somebody can explain it
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
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"
"Free software for a free society"
Dominik Michniewski wrote:In problem description says:But that not true .... integers may be less ....The next 20 integers are the values of the first 20 cards in the deck.
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.
there are always 22 integers in a line. u have some other bug.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?
-
- New poster
- Posts: 7
- Joined: Fri Mar 31, 2006 1:22 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.
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~
why i got TLE ?
i try all the test cases i can find and pass it,but still TLE...
thx for your help...
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
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
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.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
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- Experienced poster
- Posts: 139
- Joined: Wed May 18, 2011 3:04 pm
Re: 402 - M*A*S*H
The test data on uDebug:
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.
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
3 2 3 is not valid, every line contains 22 integer.
You need not to handle cases like this.
metaphysis: http://uhunt.onlinejudge.org/id/95895
My solutions for UVa problems: https://github.com/metaphysis/Code.
My solutions for UVa problems: https://github.com/metaphysis/Code.
Re: 402 - M*A*S*H
Thank you. This input has been deleted.metaphysis wrote: ↑Mon Jul 18, 2016 5:23 am The test data on uDebug: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.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
3 2 3 is not valid, every line contains 22 integer.
You need not to handle cases like this.
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