10226 - Hardwood Species

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

Moderator: Board moderators

Imti
Learning poster
Posts: 53
Joined: Sat Dec 04, 2010 12:00 pm
Location: Bangladesh
Contact:

Re: 10226 - Hardwood Species

Post by Imti » Mon May 02, 2011 1:37 pm

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
Last edited by Imti on Sun Oct 30, 2011 12:10 am, edited 1 time in total.

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 10226 - Hardwood Species

Post by plamplam » Sat Oct 29, 2011 9:28 pm

@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: )
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

Imti
Learning poster
Posts: 53
Joined: Sat Dec 04, 2010 12:00 pm
Location: Bangladesh
Contact:

Re: 10226 - Hardwood Species

Post by Imti » Sun Oct 30, 2011 12:13 am

@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

mathgirl
New poster
Posts: 36
Joined: Tue Apr 24, 2012 6:20 pm

Re: 10226 - Hardwood Species

Post by mathgirl » Mon May 07, 2012 9:25 am

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10226 - Hardwood Species

Post by brianfry713 » Mon May 07, 2012 11:51 pm

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
Check input and AC output for thousands of problems on uDebug!

csprajeeth
New poster
Posts: 5
Joined: Sat May 26, 2012 7:25 pm

Re: 10226 - Hardwood Species

Post by csprajeeth » Sun May 27, 2012 2:19 pm

Just optimize ur IO for this problem.
gets(), printf() .. and you should be fine

User avatar
@ce
Learning poster
Posts: 71
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

10226 - Hardwood Species

Post by @ce » Tue Jun 19, 2012 9:11 pm

Getting TLE...can't find a quicker way...plz help

Code: Select all

Removed
Last edited by @ce on Sun Dec 30, 2012 7:41 pm, edited 1 time in total.
-@ce

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10226 - Hardwood Species

Post by brianfry713 » Tue Jun 19, 2012 11:28 pm

Use a C++ STL map instead of a linear search.
Check input and AC output for thousands of problems on uDebug!

tzupengwang
New poster
Posts: 36
Joined: Fri Dec 02, 2011 1:30 pm
Location: Kaohsiung, Taiwan

Re: 10226 - Hardwood Species

Post by tzupengwang » Sat Aug 18, 2012 7:28 am

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

Last edited by tzupengwang on Tue Aug 21, 2012 4:43 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10226 - Hardwood Species

Post by brianfry713 » Mon Aug 20, 2012 10:51 pm

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);
Check input and AC output for thousands of problems on uDebug!

tzupengwang
New poster
Posts: 36
Joined: Fri Dec 02, 2011 1:30 pm
Location: Kaohsiung, Taiwan

Re: 10226 - Hardwood Species

Post by tzupengwang » Tue Aug 21, 2012 4:42 pm

Thanks for your advice
I get AC in 2.108s now

alimbubt
New poster
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh
Contact:

Re: 10226 - Hardwood Species

Post by alimbubt » Tue Dec 11, 2012 8:03 pm

getting TLE :( ....Plz help me....

Code: Select all

Accepted :)
Last edited by alimbubt on Fri Dec 14, 2012 8:01 pm, edited 1 time in total.
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10226 - Hardwood Species

Post by brianfry713 » Tue Dec 11, 2012 11:45 pm

getline(cin,s) is too slow, try using gets() with a char array.
Check input and AC output for thousands of problems on uDebug!

alimbubt
New poster
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh
Contact:

Re: 10226 - Hardwood Species

Post by alimbubt » Wed Dec 12, 2012 6:49 pm

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...... :(
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10226 - Hardwood Species

Post by brianfry713 » Wed Dec 12, 2012 10:09 pm

post your updated code
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 102 (10200-10299)”