网易首页 | 新闻 | 免费邮箱 | 短信 | POPO | 相册 | 搜索 | 交友 | 拍卖 | 视频 | 设为主页 | 加入珍藏    http://club.163.com
    网易社区>电脑网络

google code jam2006资格赛 250分题

作者:fn_dolphin  日期:2006-09-06 09:55:48
责任编辑:jjkkllmmnn

 
本文出自网易社区(club.163.com),如需转载,请联系原作者或网易
google code jam2006资格赛 250分题

Problem Statement
    
During a soccer match, the referee can warn players by showing them red or yellow cards. When a player is shown a red card, he is sent off the field
immediately. The first time a player is shown a yellow card, it serves as a warning. The second time he is shown a yellow card in the same match,
he is immediately shown a red card as well, and sent off the field. When players are sent off the field, they are out for the remainder of the match.
During the last World Cup, a referee forgot that one of the players was already shown a yellow card, and did not send him off after the second one.
You are to write a program to prevent such errors.
You will be given a vector info, the i-th element of which represents the i-th card shown during the match. Each element of info will be
formatted as "C NN SURNAME" (quotes for clarity only). C is a character 'Y' or 'R', representing a yellow or red card, respectively. NN is a two-digit
number representing the minute when the card was shown. SURNAME contains between 2 and 20 uppercase letters and represents the surname of the player who
was shown the card. For the purposes of this problem, we assume that surnames are unique for all players. If you find that the referee made at least one
error during the match (i.e., he showed a second yellow card to one player but didn't show him a red card at the same minute), return the earliest minute
when this happened. If the referee didn't make any errors, return -1. Please note that the referee may occasionally show more than two yellow cards to
the same player during a single minute, and this is legal as long as he also shows the red card to that player later in the same minute (see example 6).
Definition
    
Class:
RedCard
Method:
firstError
Parameters:
vector
Returns:
int
Method signature:
int firstError(vector info)
(be sure your method is public)
    

Constraints
-
All elements of info will be in chronological order. In other words, the time represented by the i-th element of info will be greater than or equal to
the time represented by the (i-1)-th element.
-
If a player is shown a red card, no later elements of info will contain that player.
-
info will contain between 0 and 50 elements, inclusive.
-
Each element of info will contain between 7 and 25 characters, inclusive.
-
Each element of info will be formatted as "C NN SURNAME".
-
In each element of info C will be either 'Y' or 'R'.
-
In each element of info NN will be a two-digit number between 00 and 90, inclusive.
-
In each element of info SURNAME will contain between 2 and 20 uppercase letters ('A' - 'Z'), inclusive.
Examples
0)

    
{"Y 10 JOHNS", "Y 70 JOHNS", "R 70 JOHNS"}
Returns: -1

1)

    
{"Y 10 JOHNS", "R 70 JOHNS"}
Returns: -1

2)

    
{"Y 10 JOHNS", "Y 10 SMITH", "Y 20 JOHNS", "Y 20 SMITH", "R 20 SMITH", "R 20 JOHNS"}
Returns: -1
Both red cards are shown at the same minute as the second yellow cards, so the referee didn't make any error here.
3)

    
{"Y 10 JOHNS", "Y 15 JOHNS", "Y 70 JOHNS", "R 70 JOHNS"}
Returns: 15

4)

    
{"Y 10 SMITH", "Y 13 WILLIAMS", "Y 70 SMITH", "Y 70 JOHNS",
"R 70 SMITH", "Y 71 JOHNS", "R 71 JOHNS", "R 90 WILLIAMS"}
Returns: -1

5)

    
{
"Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS",
"Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS",
"Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS",
"Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS",
"Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 02 JOHNS"
}
Returns: 1
Both Johns and the referee were really active from the very beginning of the game.
6)

    
{
"Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS",
"Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "R 01 JOHNS"
}
Returns: -1

还没比赛的选手不妨参考一下。
本文出自网易社区(club.163.com),如需转载,请联系原作者或网易

    原文地址:

  竞价广告:




  精彩文章
·世界上最贵的十幅画
·如何请老人搬出去住
·世界第一豪宅被中国人买
·超级女声-金箔包的月饼
·这个九月-原创多图
·回忆童年-虐鼠记
·视频的感觉真好
·东京审判的感想与反思
·世界屋脊之旅 130张图
·印度印象:满街绝色美人
  大区精选
·投票:最不般配荧幕情侣
·一个老男人的婚后生活
·纯美Twins婚纱照
·7件小事让皮肤越变越好
·新房验收的十个小窍门
·极品碧玺“福水晶”
·解密:你适合和谁谈恋爱
·汶川大地震一月祭
·寻根问底的古代姓氏宗族
·挨千刀的余秋雨
  编辑推荐
·各国奥运会入场礼服
·也说“人肉搜索”
·80后的十大烦恼
·古玩收藏行话术语
·无冕皇帝与狗仔队
·与结婚有关的这些事
  社区动态
 

About NetEase - 公司简介 - 联系方法 - 招聘信息 - 客户服务 - 相关法律 - 广
网易公司版权所有 ©1997-2008
网易社区市场联系POPO:detenele