【map&pair】#81 A. Transmigration

来源:互联网 发布:你瞒我瞒网络歌手 编辑:程序博客网 时间:2024/06/09 17:14

A. Transmigration
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills.

Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration.

Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life.

As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where[y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0.

Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible.

You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be?

Input

The first line contains three numbers nm and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and mare integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 200.01 ≤ k ≤ 0.99).

Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive.

Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates.

All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names.

Output

Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order.

Sample test(s)
input
5 4 0.75axe 350impaler 300ionize 80megafire 120magicboost 220healmegafireshieldmagicboost
output
6axe 262heal 0impaler 225magicboost 165megafire 0shield 0


这是一个游戏党出的题,原先你有这么多技能,右边是熟练度或者记忆度之类的东西,然后你学习了一些技能的同时以一个比率对已有技能的记忆能力降低成这个比率的数值(遗忘),以前没学过的技能就是0熟练度,学过的技能如果低于100就被忘掉了,问这次学习之后还剩多少技能以及他们的熟练度。

这里我用了map的数据结构,将string和int绑在一起用map是很棒的哦~

先make_pair(str,int*rate) 然后把整数部分不小于100的pair给push进map中,判断新学技能有没有原先不会的,有的话push进去(int部分是0哦)。

最后把map里的东西都打印出来即可。


Code

#include <map>#include <cstdio>#include <string>#include <cstring> #include <iostream>#include <algorithm>using namespace std;typedef long long ll;// http://codeforces.com/contest/105// Transmigrationmap<string,int> mp;int main(){int n,m;double rate;cin>>n>>m>>rate;int rat=(int)(rate*100);for(int i=0;i<n;i++){string name;double p;cin>>name>>p;int pp=p*rat/100;if(pp>=100)mp.insert(make_pair(name,pp));}for(int i=0;i<m;i++){string name;cin>>name;if(mp[name]==0)mp.insert(make_pair(name,0));}cout<<mp.size()<<endl;for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++){cout<<it->first<<" "<<it->second<<endl;}return 0;} 




0 0
原创粉丝点击