Page 6 of 9

Re: 10226 - Hardwood Species

Posted: Mon May 02, 2011 1:37 pm
by Imti
shafayet_du,would u plz check ur output again?bcz my progrm is showing otherwise,Though my code is not accepted,I checked my output with Uva toolkit output and ur printing this line twice "what the hell is this tree 2.5000"..
However,I made a lot of input to test my code..I guess it passed all of it..But Im getting WA..can there be any input like a blank line,i mean,suppose input is like

Code: Select all

1
//This is the blank line after test case
//Instead of any tree a blank line is given
If such case exist,What should be output?I'm giving my code below,I used BST to solve the problem..

Code: Select all

//cut after getting accepted

Re: 10226 - Hardwood Species

Posted: Sat Oct 29, 2011 9:28 pm
by plamplam
@Imti his output is correct. I am afraid you overlooked an extra space. Just use a structure, sort and binary search. And remember to print a blank line between cases. There are no extra blanks or extra spaces or anything...just take the inputs with gets() and handle doubles carefully.
by sazzadcsedu ยป Mon May 24, 2010 8:40 pm
This problem can be solved by stl map && priority queue.And its running time is good.my Acc program run in 2.428s(current ranking 280).
Yeah I agree but sort + binary search gets Accepted in less than 1s...and its easier to implement(May be because I just copied those functions from another code of mine :roll: )

Re: 10226 - Hardwood Species

Posted: Sun Oct 30, 2011 12:13 am
by Imti
@plamplam
ur exact about my fault.I overlooked a blank space character .after fixing it I got accepted.BTW,thanks for ur reply.In fact I forgot about this problem and ur post made me give a look back at it.... :D

Re: 10226 - Hardwood Species

Posted: Mon May 07, 2012 9:25 am
by mathgirl
I m getting WA using STL. I wont be surprised if i got TLE, but what's wrong with this code?

Code: Select all

#include<map>
#include<iostream>
#include<string>
#include<iomanip>

using namespace std;

int main()
{
	int t;
	cin>> t;
	string tree,empty;
	getline(cin,empty);
	
	while(t)
	{
		map<string,double> trees;
		getline(cin,empty);		

		double total=0.0;
		while(getline(cin,tree) && !tree.empty())
		{
			trees[tree]++;
			total++;
		}

		map<string,double>::const_iterator iter = trees.begin();

		while(iter!= trees.end())
		{
			double percent = (iter->second/total) * 100;
			cout << iter->first << " ";
			cout<<setprecision(4)<<setiosflags(ios::fixed) << percent << "\n";
			iter++;
		}
		
		if(t > 1)
			cout << "\n";
		t--;
	}
	return 0;
}

Re: 10226 - Hardwood Species

Posted: Mon May 07, 2012 11:51 pm
by brianfry713
Input:

Code: Select all

2

Red Alder
Ash
Aspen
Basswood
Ash
Beech
Yellow Birch
Ash
Cherry
Cottonwood
Ash
Cypress
Red Elm
Gum
Hackberry
White Oak
Hickory
Pecan
Hard Maple
White Oak
Soft Maple
Red Oak
Red Oak
White Oak
Poplan
Sassafras
Sycamore
Black Walnut
Willow

Red Alder
Ash
Aspen
Basswood
Ash
Beech
Yellow Birch
Ash
Cherry
Cottonwood
Ash
Cypress
Red Elm
Gum
Hackberry
White Oak
Hickory
Pecan
Hard Maple
White Oak
Soft Maple
Red Oak
Red Oak
White Oak
Poplan
Sassafras
Sycamore
Black Walnut
Willow
Output should be:

Code: Select all

Ash 13.7931
Aspen 3.4483
Basswood 3.4483
Beech 3.4483
Black Walnut 3.4483
Cherry 3.4483
Cottonwood 3.4483
Cypress 3.4483
Gum 3.4483
Hackberry 3.4483
Hard Maple 3.4483
Hickory 3.4483
Pecan 3.4483
Poplan 3.4483
Red Alder 3.4483
Red Elm 3.4483
Red Oak 6.8966
Sassafras 3.4483
Soft Maple 3.4483
Sycamore 3.4483
White Oak 10.3448
Willow 3.4483
Yellow Birch 3.4483

Ash 13.7931
Aspen 3.4483
Basswood 3.4483
Beech 3.4483
Black Walnut 3.4483
Cherry 3.4483
Cottonwood 3.4483
Cypress 3.4483
Gum 3.4483
Hackberry 3.4483
Hard Maple 3.4483
Hickory 3.4483
Pecan 3.4483
Poplan 3.4483
Red Alder 3.4483
Red Elm 3.4483
Red Oak 6.8966
Sassafras 3.4483
Soft Maple 3.4483
Sycamore 3.4483
White Oak 10.3448
Willow 3.4483
Yellow Birch 3.4483

Re: 10226 - Hardwood Species

Posted: Sun May 27, 2012 2:19 pm
by csprajeeth
Just optimize ur IO for this problem.
gets(), printf() .. and you should be fine

10226 - Hardwood Species

Posted: Tue Jun 19, 2012 9:11 pm
by @ce
Getting TLE...can't find a quicker way...plz help

Code: Select all

Removed

Re: 10226 - Hardwood Species

Posted: Tue Jun 19, 2012 11:28 pm
by brianfry713
Use a C++ STL map instead of a linear search.

Re: 10226 - Hardwood Species

Posted: Sat Aug 18, 2012 7:28 am
by tzupengwang
I'm getting TLE now
I am using getline() and cout()
I'm wondering how to read &write"string" with gets() and printf()
or how to convert string with *char
the following is my code~
Can anyone help?

Code: Select all

/*10226*/
Removed after AC


Re: 10226 - Hardwood Species

Posted: Mon Aug 20, 2012 10:51 pm
by brianfry713
No species name exceeds 30 characters. Try something like:

Code: Select all

while(gets(line)&&line[0])
{
  string in(line);
...
printf("%s %.4lf\n", it->first.c_str(), double(it->second)/total*100);

Re: 10226 - Hardwood Species

Posted: Tue Aug 21, 2012 4:42 pm
by tzupengwang
Thanks for your advice
I get AC in 2.108s now

Re: 10226 - Hardwood Species

Posted: Tue Dec 11, 2012 8:03 pm
by alimbubt
getting TLE :( ....Plz help me....

Code: Select all

Accepted :)

Re: 10226 - Hardwood Species

Posted: Tue Dec 11, 2012 11:45 pm
by brianfry713
getline(cin,s) is too slow, try using gets() with a char array.

Re: 10226 - Hardwood Species

Posted: Wed Dec 12, 2012 6:49 pm
by alimbubt
brianfry713 wrote:getline(cin,s) is too slow, try using gets() with a char array.
I have used gets() and char array....But again TLE...... :(

Re: 10226 - Hardwood Species

Posted: Wed Dec 12, 2012 10:09 pm
by brianfry713
post your updated code