UVa 10226

From Algorithmist
Jump to navigation Jump to search
This is a stub or unfinished. Contribute by editing me.

10226 - Hardwood Species[edit]

Summary[edit]

You are about to find out what is the percentage of each tree with respect to total number of trees.

Explanation[edit]

There is given the name of trees in any order. You have to find what is the percentage of appearence of unique trees in alphabetical order. Imaging the names of trees are:

aa
xx
aa

then, aa is 66.6667%, and xx is 33.3333%.

Gotchas[edit]

  • The character set is not defined in the question. Any character can be given. NOT only alphabetical letter and space.
  • Character from range [0,128] is enough for thinking.

Notes[edit]

  • DATA set is huge. Without proper handling, it'll give you TLE.

Implementations[edit]

Optimizations[edit]

You can use Trie. It's quite good data structure for this problem.


struct node{
    int cnt_trees;
    node *child[128];
    node()
    {
        cnt_trees = 0;
        for(int i=0; i<128; i++)
        {
            child[i] = NULL;
        }
    }
}*head;

Input[edit]

1

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[edit]

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

References[edit]

  1. References

Categories here, use the form [[Category:UVa Online Judge|10226]] [[Category: Category Name]], see Categories for a list