But that not true .... integers may be less ....The next 20 integers are the values of the first 20 cards in the deck.
402 - M*A*S*H
Moderator: Board moderators
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
-
- New poster
- Posts: 8
- Joined: Tue Jul 23, 2002 9:15 am
GIVE SOME TEST INPUT FOR 402
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..
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
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
-
- New poster
- Posts: 8
- Joined: Tue Jul 23, 2002 9:15 am
YOU ARE TOO SHORT
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...
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
-
- 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
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
[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
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
-
- Learning poster
- Posts: 68
- Joined: Fri Oct 26, 2001 2:00 am
- Location: Dhaka, Bangladesh
- Contact:
i changed, but no change in judge reply....
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]
[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]
I ignore this sample,but I still got Acceptd..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 thougth the judge dosen't have this case.
402 M*A*S*H wrong answer
![:oops:](./images/smilies/icon_redface.gif)
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]
Why?
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
Can someone please explain why this should happen?Adrian Kuegel:
Output is:
Selection #1
1 2 3 4 5 6 11 19
*****SeaViperz*****
Draw your fangs and let's duel.
For my poison serves forever as my fuel!
Draw your fangs and let's duel.
For my poison serves forever as my fuel!
Re: WA Still
This prob's special case is very much!manir wrote: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
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!
Why is 402 - M*A*S*H Runtime error (SISEGV)?
[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!!
#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!!
402 Why WA
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.
[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.