読者です 読者をやめる 読者になる 読者になる

sonoshouのまじめなブログ

情報系大学生からのウェブ見習い人生の記録

codeforces初参戦!

f:id:sonoshou:20110814023453p:image

「今日プログラミングコンテストあるからお前も出ろよ!」

「うん!わかった!ボク・・・・・出てみるよ!!」

というわけでcodeforcesというプログラミングコンテストに参加しました。
問題が出題され、解けたら順に提出していく。
全部で5題。問題を解くまでの速さを競うコンテストです。

ここまでだと普通のプログラミングコンテストと変わらないのですが、
特徴としては使用できる言語が比較的多いところでしょうか。

僕はpythonを選択!pythonを覚えたかったので良い機会です。

その結果、sonoshouの実力は5題中1問。不甲斐ない結果だ・・・・・・。
pythonの文法がわからなくて、pythonでの配列や辞書の使い方を
ググりながらだったとしても(言い訳)、この結果はひどすぎる。

精進していきたいです・・・・・・。

ってか最近ほんと自分はプログラマ向いてないと思う。
周りの人たちのレベルについていける気がしない・・・・・・。



codeforces始まった!と思ったら、
なぜかディスガイア(ゲーム)の画像がトップに!!
どうやら問題の題材が今回はディスガイアなようです。
なかなか粋なことしてくれますね。

プログラミングコンテストはこういったゲームとのコラボや時事ネタなどがよく入っていて、
問題を読んでいてクスリと笑ってしまうことが多い気がする。
大好きなのでもっとやってください。



1問目しか解けなったので、1問目の紹介だけしますかね・・・・・・。

本家サイトはコチラ
A. Transmigration

A. Transmigration

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 n, m 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 m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.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.75
axe 350
impaler 300
ionize 80
megafire 120
magicboost 220
heal
megafire
shield
magicboost

output

6
axe 262
heal 0
impaler 225
magicboost 165
megafire 0
shield 0

My Answer (python)

# -*- coding: utf-8 -*-
'''
Created on 2011/08/14

@author: me
'''

#n m k を読み込む
input = raw_input()
inputSplit = input.split(' ')

n = int(inputSplit[0])
m = int(inputSplit[1])
k = float(inputSplit[2])

#各種辞書を宣言
ability1 = {}
ability2 = {}
new_ability = {}

#転生前のスキル名とスキルポイントを辞書に代入
for i in range(0, n):
    input2 = raw_input()
    arrInput2 = input2.split(' ')
    ability1[arrInput2[0]] = int(arrInput2[1])
    
#転生後の職のスキルを配列に代入
for j in range(0, m):
    input3 = raw_input()
    ability2[j] = input3
    
#転生前から覚えていたスキル各々に対して、転生後のスキルレベルを計算
#スキルレベルが100以上だったら、転生後のスキルとして確定するので、new_ability辞書に代入
for key, value in ability1.items():
    new_value = value * k
    if(new_value >= 100):
        new_ability[key] = new_value

#転生前に覚えていなくて、転生後に覚えるスキルを選別し、new_ability辞書に代入
for value2 in ability2:
    flag = 0
    for key1, value1 in new_ability.items():
        if(ability2[value2] == key1):
            flag = 1
    if(flag == 0):
        new_ability[ability2[value2]] = 0

#結果を出力
print len(new_ability)
for key, value in sorted(new_ability.items()):
    intValue = int(value)
    print key,intValue