119 - Greedy Gift Givers

All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore

I tried it Abhishek

Post by aakash_mandhar »

i tried that but i still get wa...
:evil: i am angry.........

anyways thx for the help..
did u get accepted..

plz try with my code itself...

Aakash
...I was born to code...
abishek
Experienced poster
Posts: 131
Joined: Mon Dec 15, 2003 5:41 am

Post by abishek »

obviously you don't subtract the cash that you have from you when the number of ppl is 0.

try again
best of luck
[cpp]

if(strcmp(a[j],name)==0) {money[j]-=cash;if(people) money[j]+=cash%people; break;}
[/cpp]
WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR »

Hi,

I don't think this is a multiple input problem as it has no blue tick mark.

There are just several test cases with no blank lines between them.

But of course I could be wrong which would explain the Wrong Answer my program gets. Perhaps somebody could verify the following I/O and add more cases?

input:

Code: Select all

5
dave laura owen vick amr
dave 200 3 laura owen vick
owen 500 1 dave
amr 150 2 vick owen
laura 0 2 amr vick
vick 0 0
3
liz steve dave
liz 30 1 steve
steve 55 2 liz dave
dave 0 2 steve liz
1
mary
mary 20 0
2
123456789012 123456789012
123456789012 0 0
123456789012 0 0
2
noim nahid
noim 10 0
nahid 9 0
2
one two
one 100 0
two 10 1 one
output:

Code: Select all

dave 302
laura 66
owen -359
vick 141
amr -150

liz -3
steve -24
dave 27

mary 0

123456789012 0
123456789012 0

noim 0
nahid 0

one 10
two -10
jagadish
Learning poster
Posts: 90
Joined: Mon Feb 16, 2004 8:53 pm
Location: Bangalore INDIA

Post by jagadish »

my AC program gives the same output..but u hardly have any test cases :)

anyway let me know the output for this one
10
dave laura owen vick amr
dave2 laura2 owen2 vick2 amr2

dave 200 0
owen 500 1 dave
amr 150 2 vick owen
laura 0 2 amr vick
vick 0 0
dave2 200 0
owen2 500 1 dave
amr2 150 2 vick owen
laura2 0 2 amr vick
vick2 100 0




if u can think of it .. u can do it in software.
jagadish
Learning poster
Posts: 90
Joined: Mon Feb 16, 2004 8:53 pm
Location: Bangalore INDIA

Post by jagadish »

change this
while(scanf("%d",&nPerson)) to while(scanf("%d",&nPerson)==1) :)
if u can think of it .. u can do it in software.
WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR »

To jagadish:

Got your point!

Thanks a lot.

My program gives:

Code: Select all

dave 1000
laura 0
owen -350
vick 150
amr -150
dave2 0
laura2 0
owen2 -500
vick2 0
amr2 -150
iyxm2000
New poster
Posts: 1
Joined: Wed Jul 07, 2004 3:37 pm

119-Why WA??

Post by iyxm2000 »

#include "string.h"
#include "iostream.h"
#include "stdio.h"
class Person
{
public:
char name[13];
long in;
long out;
Person(char *s)
{
strcpy(name,s);
in=0;
out=0;
}
Person()
{
in=0;
out=0;
}
};

int main()
{
int n;
char temp[13];
while(cin>>n)
{
Person *givers=new Person[n];
for(int i=0;i<n;i++)
{
cin>>(givers+i)->name;
}
int outnum;
int tout;
for(int j=0;j<n;j++)
{
int x;
cin>>temp>>tout>>outnum;
int p;
for(p=0;p<n;p++)
{
if(!strcmp((givers+p)->name,temp))
{
(givers+p)->out+=tout;
x=p;
break;
}
}
for(int k=0;k<outnum;k++)
{
cin>>temp;
for(int l=0;l<n;l++)
{
if(!strcmp((givers+l)->name,temp))
{
(givers+l)->in=(givers+l)->in+tout/outnum;
break;
}
}
}
if(outnum!=0)
(givers+p)->out=((tout/outnum)*outnum);
}
for(int m=0;m<n;m++)
{
cout<<(givers+m)->name<<" "<<(((givers+m)->in)-((givers+m)->out))<<endl;
}
cout<<endl;
}

return 0;
}
GreenPenInc
Learning poster
Posts: 53
Joined: Sat May 01, 2004 9:31 pm
Contact:

Post by GreenPenInc »

It might have something to do with the fact that you set the out field twice. On line 45 you update the total (although it's guaranteed to be zero, so you might as well clobber it) then around line 63 you actually do clobber it, but conditionally. If somebody were to give a nonzero amount of money to zero friends, you would no longer have a zero sum.

Or maybe it's because you use antiquated headers; I don't know.
_-(GPI)-_

"Finally I have freed myself from the clutches of the garbage fairy!"
Karthekeyan
New poster
Posts: 33
Joined: Tue Jun 29, 2004 1:38 pm
Location: IITM,chennai,Tamil Nadu,India
Contact:

119-Why WA?

Post by Karthekeyan »

Here's my code...Can someone help me find why I get wrong answer frm the Judge..

Code: Select all

[cpp]

#include<iostream>
#include<string>
using namespace std;
main()
{
  int n;
  while(cin>>n)
    {
      char names[10][13],name[10][13],giftto[10][10][13];
      int i,amount[10],ppl[10],j,profit[10],l,loss[i];
      for(i=0;i<n;i++)
	{
	  cin>>names[i];
	}
      for(i=0;i<n;i++)
	{
	  cin>>name[i]>>amount[i]>>ppl[i];
	  for(j=0;j<ppl[i];j++)
	    {
	      cin>>giftto[i][j];
	    }
	}
      for(i=0;i<10;i++)
	{
	  profit[i]=0;
	  loss[i]=0;
	}
      for(i=0;i<n;i++)
	{
	  for(j=0;j<ppl[i];j++)
	    {
	      for(l=0;l<n;l++)
		{
		  if(strcmp(name[l],giftto[i][j])==0)
		    {
		      profit[l]+=amount[i]/ppl[i];
		      loss[i]-=amount[i]/ppl[i];
		    }
		}
	    }
	}
      for(i=0;i<n;i++)
	{
	  profit[i]+=loss[i];
	}
      for(i=0;i<n;i++)
	{
	  for(j=0;j<n;j++)
	    {
	      if(strcmp(name[j],names[i])==0)
		  {
		    cout<<names[i]<<" "<<profit[j]<<'\n';
		  }
	    }
	}
      cout<<" ";      
    }

  return(0);
}
[/cpp]
Can someone atleast give me some sample i/o so that I find the mistake.
gibber
New poster
Posts: 2
Joined: Mon Jul 12, 2004 6:36 am

Post by gibber »

Your program has a mistake,please look at the tenth line of your program,you can't declare loss like this:" loss",it's not like vector.Just declare loss like this:" loss[10000]",you will get AC.Good lucky to you! :wink:(I'm not good at English,I hope you can understand what I say :oops: )
I enjoy programming!!!
Karthekeyan
New poster
Posts: 33
Joined: Tue Jun 29, 2004 1:38 pm
Location: IITM,chennai,Tamil Nadu,India
Contact:

yeah...I changed that mistake...Yet it says WA for 119

Post by Karthekeyan »

Thanx a lot...But still it doesnt accept the prg.It still says it is a wrong answer...Pls,someone give me a sample i/o...
Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

Just take a look at the previous posts about this problem in this foruam. You will find a lot of sample I/O.
Karthekeyan
New poster
Posts: 33
Joined: Tue Jun 29, 2004 1:38 pm
Location: IITM,chennai,Tamil Nadu,India
Contact:

Its running on all the given i/o s

Post by Karthekeyan »

Sorry Raiyan.

I hav checked with the i/os from this forum by checking with the board...
Thanx for ur concern....
Karthe
vadiu
New poster
Posts: 10
Joined: Mon Jul 19, 2004 6:35 pm

119 - Greedy Gift Givers

Post by vadiu »

I have read all the posts about this problem and tried all the "strange\special" cases and my program gives me good results. But when i submit it he gives me Wrong Answers. I can't understand why. :-? Any help would be greatly appreciated. Thanks...

[c]
#include "stdio.h"
#include "string.h"

void less();
void contabilizar();

int a, b, iterator, d, group, cash, number;
char giver[14];
char person[14];
FILE *in, *out;

struct pessoa{
int money;
char nome[10];
}list[10];

void less()
{
for(iterator=0; iterator<group; iterator++)
{
if(!strcmp(list[iterator].nome, giver))
{
if(cash==0)
break;
d=cash/number;
list[iterator].money-=d*number;
break;
}
}
}

int main()
{

in=stdin;
out=stdout;

while(fscanf(in, "%d", &group)!=EOF)
{

for(a=0; a<group;a++)
fscanf(in, "%s", &list[a].nome);

for(a=0; a<group; a++)
{
fscanf(in, "%s", giver);
fscanf(in, "%d %d", &cash, &number);

for(b=0; b<number; b++)
{
fscanf(in, "%s", person);
contabilizar();
}
if(number!=0)
less();
}

for(a=0; a<group; a++)
fprintf(out, "%s %d\n", list[a].nome, list[a].money);

for(a=0; a<group; a++)
list[a].money=0;

putchar('\n');

}

return 0;
}

void contabilizar()
{
for(iterator=0; iterator<group; iterator++)
{
if(!strcmp(list[iterator].nome, person))
{
list[iterator].money+=cash/number;
break;
}
}
}
[/c]
Zuberul
New poster
Posts: 28
Joined: Sun Oct 24, 2004 9:46 pm
Location: dhaka
Contact:

119-sample I/O

Post by Zuberul »

I cant find out why WA.
My code got Accepted on the usaco judge but wa here.
what is the case?
give me some sample I/O.
Post Reply

Return to “Volume 1 (100-199)”