154 - Recycling

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

User avatar
dumb dan
Learning poster
Posts: 67
Joined: Tue Aug 05, 2003 1:02 am

Post by dumb dan » Tue Oct 05, 2004 10:32 am

You might want to initilize min to something larger than 6.
min=500 should suffice.

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

Post by Morning » Tue Oct 05, 2004 10:36 am

yeah,that's a mistake.but after changed it to 600,i still keep getting WA
[cpp]
#include <iostream>
#include <cstring>
using namespace std;
int calculate(char data[101][5][4],int n)
{
int min = 600,sum,record;
for(int i = 0;i < n;i++)
{
sum = 0;
for(int j = 0;j < n;j++)
{
if(j == i) continue;
for(int k = 0;k < 5;k++)
{
if(strcmp(data[k],data[j][k]) != 0)
{
sum++;
}
}
}
if(sum < min)
{
min = sum;
record = i;
}
}
return record + 1;
}
int main()
{
int i,n = 0;
char string[20];
char data[101][5][4];
char seps[] = ",";
char *token;
while(cin >> string)
{
if(string[0] == 'e')
{
cout << calculate(data,n) << endl;
n = 0;
continue;
}
if(string[0] == '#') {break;}
token = strtok( string, seps );
i = 0;
while( token != NULL )
{
strcpy(data[n][i++],token);
token = strtok( NULL, seps );
}
n++;

}
return 0;
}[/cpp]
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

User avatar
dumb dan
Learning poster
Posts: 67
Joined: Tue Aug 05, 2003 1:02 am

Post by dumb dan » Tue Oct 05, 2004 11:22 am

input:

Code: Select all

g/N,y/G,o/S,r/A,b/P
y/N,b/S,r/G,g/A,o/P
r/N,y/G,o/S,b/P,g/A
e
r/A,y/G,o/S,b/P,g/N
r/G,y/N,o/P,b/S,g/A
r/N,y/G,o/S,b/P,g/A
e
#
output:

Code: Select all

3
3

Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

Post by Morning » Tue Oct 05, 2004 11:31 am

yeah,i got what u mean,they are not in order,now i got AC.Thanks
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

rjhadley
Learning poster
Posts: 73
Joined: Mon Oct 14, 2002 7:15 am
Location: United States

Post by rjhadley » Sat Feb 26, 2005 10:49 am

Almost Human wrote:Try the following input:
r/G,o/P,y/S,g/A,b/N
r/P,o/S,y/G,g/A,b/N
r/G,o/P,y/S,g/A,b/N
e
#

your program produces :
3

the correct one should produces :
1
Your input here is ambiguous. However,
Problem Specification wrote:Note that there will always be a clear winner.

58050zz
New poster
Posts: 38
Joined: Sat Feb 26, 2005 8:13 am

How to input

Post by 58050zz » Sun Feb 27, 2005 12:44 pm

Code: Select all

  	string s=
"r/P,o/G,y/S,g/A,b/N"
"r/G,o/S,y/A,g/P,b/N"
"r/G,o/S,y/A,g/P,b/N"
"e"
"#";
if i initialize the string
i can run my code
..
how to input like the (initialize) format
without garbage data (ex:space)
when i encounter space.will bug

dootzky
New poster
Posts: 36
Joined: Tue Apr 12, 2005 12:20 am
Location: belgrade, serbia (ex yugoslavia)
Contact:

Post by dootzky » Tue May 31, 2005 12:42 am

damn ppl, this problem was really really badly described.
if it waren't for "almost human" dude, i would've never get ACC.

someone should do a better job when describing problems, like in volumes 600,700,etc.

first couple of volumes has terrible, terrible descriptions.

thx for the help, "almost human" mon!

ReSpeCT,
dootzky

ldaniele
New poster
Posts: 6
Joined: Sat Aug 12, 2006 2:26 am

154 Why i get WA??

Post by ldaniele » Mon Aug 21, 2006 9:55 pm

#include<iostream>
#include<string>

#define PROVA
#ifdef PROVA

#include<fstream>

using std::ofstream;
using std::ifstream;
using std::string;
//using std::cout;
ofstream cout("output.txt");
ifstream cin("input.txt");

#endif
#ifndef PROVA

using std::cin;
using std::cout;
using std::string;

#endif

//variabili globali
const short int rows=500, cols=5;
//matrice citt

ldaniele
New poster
Posts: 6
Joined: Sat Aug 12, 2006 2:26 am

Re: 154 Why i get WA??

Post by ldaniele » Tue Aug 22, 2006 5:26 pm

I've solved, so you can delete the code!!!

razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia

Post by razor_blue » Sat Dec 16, 2006 7:28 am

I don't know why my code is wrong.
Do you know my mistake?

Code: Select all

/* removed after AC */
Last edited by razor_blue on Sat Dec 23, 2006 2:49 am, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Sat Dec 16, 2006 11:51 am

If there is only one city its clear that it should be the winner. Check the samples...

Input:

Code: Select all

g/A,b/N,y/S,o/G,r/P
e
r/P,b/N,o/G,g/A,y/S
e
b/N,y/S,g/A,r/P,o/G
e
#
Output:

Code: Select all

1
1
1
Hope these help.
Ami ekhono shopno dekhi...
HomePage

razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia

Post by razor_blue » Sat Dec 23, 2006 2:48 am

Thank you Jan, I added in my program:

Code: Select all

if(num_city==1) return 1;
and I got AC. :D

ata
New poster
Posts: 2
Joined: Wed Nov 07, 2007 5:54 pm
Location: BANGLADESH

wa ...anyone help

Post by ata » Mon Jan 07, 2008 7:49 pm

i have tested the test inputs in the forum....
can anyone plz tell me why my program gives wa...
here is my code...

Code: Select all

#include<stdio.h>
#include<string.h>

char recycle[6]="PGASN";
char waste[6]="roygb";
int city[100][5];
int result[100];

int find_max(int x[],int num)
{
	int max,i,index;
	max=0;
	for(i=0;i<num;i++)
		if(result[i]>max)
		{
			max=result[i];
			index=i;
		}
	return index;
}
int main()
{
	
	char temp[30];
	int cit,x,i,j,k,num,n;	
	char c,cc;
	cit=0;
	while(scanf("%s",&temp)==1)
	{
		if(strcmp(temp,"#")==0)
			break;

		if(temp[0]=='e')
		{
			if(cit==1)
			{
				printf("1\n");
				continue;
			}
			num=cit;	
			cit=0;
			i=0;
			n=0;
			for(i=0;i<num;i++)
				result[i]=0;
			n=0;
			while(n<num)
			{
				for(i=0;i<num;i++)
				{
					if(n==i)
						continue;
					for(j=0;j<5;j++)
					{	
						if(city[n][j]==city[i][j])
							result[n]++;
					}
				}
			n++;
			}
			printf("%d\n",find_max(result,num)+1);
			continue;
		}
		
		for(k=0;k<strlen(temp);k=k+4)
		{		
			c=temp[k];
			cc=temp[k+2];
		
			j=0;
			while(c!=waste[j])
				j++;
		
			x=0;
			while(cc!=recycle[x])
				x++;

			city[cit][j]=x;
		}
		cit++;
						
	}
	return 0;
}
thanx in advance for any help

alirezanoori
New poster
Posts: 26
Joined: Fri Jan 02, 2009 12:41 am

Re: 154 : Recycling

Post by alirezanoori » Thu Feb 26, 2009 12:52 pm

I am getting WA too, and my algorithm is pretty much the same as yours. I debugged my program and it works as expected but I don't know why I am getting WA! I think there is some critical inputs because I am sure this is the right algorithm.
If anyone has some critical inputs please post it.
If you need my code I am ready to post it here. Just tell me.
Thanks.

kissu parina
New poster
Posts: 19
Joined: Thu May 20, 2010 8:58 am

Re: WA 154

Post by kissu parina » Fri Feb 11, 2011 7:31 am

thnkx to almost human
one day...

Post Reply

Return to “Volume 1 (100-199)”