题目链接:http://codeforces.com/contest/493/problem/A

题目意思:给出两个字符串,分别代表 home 和 away。然后有 t 个player,每个player偶四个属性描述:分钟,所属的队名(即上面的两个字符串的其中一个),该player的num,得到的card颜色(y/r)。 当一个人得到两个y card 时会自动转为 r card。最终需要按时间先后的顺序输出player第一次获得red card 的时间。

  由于数据是按时间先后顺序排列的,那么对于某个player,如果得到 r card,就可以直接输出答案了。然后得到 y card,要先用vis数组记录,如果再次遇到该player 且 vis数组已经被标记,那么这个player 符合条件,直接输出答案。注意,输出答案之后要标记这个player已经被处理。

  输入搞了好长时间,看来几天不写代码,确实容易退化啊~~~~

  (1)124ms  版本(这个可以忽略)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = + ;
const int N = + ; char home[maxn], away[maxn];
int vish[N], visa[N];
bool non_delth[N], non_delta[N]; int main()
{
char belong, card;
int t, minute, num;
while (cin >> home >> away)
{
memset(vish, , sizeof(vish));
memset(visa, , sizeof(visa)); memset(non_delta, false, sizeof(non_delta));
memset(non_delth, false, sizeof(non_delth)); cin >> t;
for (int i = ; i < t; i++)
{
cin >> minute >> belong >> num >> card;
if (belong == 'h')
{
if (!non_delth[num])
{
if (card == 'r' || vish[num])
{
printf("%s %d %d\n", home, num, minute);
non_delth[num] = true;
}
else
vish[num] = ;
}
}
else if (belong == 'a')
{
if (!non_delta[num])
{
if (card == 'r'|| visa[num])
{
printf("%s %d %d\n", away, num, minute);
non_delta[num] = true;
}
else
visa[num] = ;
}
}
}
}
return ;
}

(2)15 ms版本(简单 + 方便 + 短小 + 容易理解)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int N = + ;
string s[];
int f[][N]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int minute, num, n;
char belong, card;
while (cin >> s[] >> s[] >> n)
{
memset(f, , sizeof(f));
for (int i = ; i < n; i++)
{
cin >> minute >> belong >> num >> card;
int c1, c2;
c1 = (belong == 'h' ? : );
c2 = (card == 'y' ? : ); if (f[c1][num] < )
{
f[c1][num] += c2;
if (f[c1][num] >= )
cout << s[c1] << " " << num << " " << minute << endl;
}
}
}
return ;
}

   

 注:最巧妙的一句在

 if (f[c1][num] < 2)

 这句话能够排除  在一个队里面同一个人当遇到多次(四次以上) yellow card 时只输出一次,符合题目要求!

codeforces 493A. Vasya and Football 解题报告的更多相关文章

  1. codeforces 460A Vasya and Socks 解题报告

    题目链接:http://codeforces.com/problemset/problem/460/A 题目意思:有一个人有 n 对袜子,每天早上会穿一对,然后当天的晚上就会扔掉,不过他会在 m 的倍 ...

  2. codeforces 493B.Vasya and Wrestling 解题报告

    题目链接:http://codeforces.com/problemset/problem/493/B 题目意思:给出 n 个 techniques,每个 technique 的值为 ai. ai & ...

  3. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  4. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...

  5. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  6. codeforces 507B. Amr and Pins 解题报告

    题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...

  7. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...

  8. codeforces B. Xenia and Ringroad 解题报告

    题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...

  9. Codeforces Round #262 (Div. 2)解题报告

    详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http ...

随机推荐

  1. oracle 中的Ipad()函数

    本文基于转载: lpad函数从左边对字符串使用指定的字符进行填充.lpad意思是从左边填充的意思. 语法格式如下: lpad( string, padded_length, [ pad_string ...

  2. HTML5音乐播放器(最新升级改造加强版)

    最近么,单位里面么老不顺心的,公司一直催要程序员要PHP,然后本宅好不容易推荐了一个,我日嘞,最后待遇变成1.3,吾师最后也同意1.3W,然后还说要考虑... 尼玛,4年多5年不到一点的工作经验,前端 ...

  3. Jquery 操作IFrame

    使用jquery操作iframe 1. 内容里有两个ifame <iframe id="leftiframe"...</iframe> <iframe id ...

  4. Win7与XP共享互相访问及共享注意事项!

    win7共享方法和XP类似,主要需要检查以下操作: 1,首先将Guest账户打开 2,右击文件夹-属性-共享选项-高级共享 3,将共享文件√打上,应用-确定即可! 4,查看自己IP(开始-运行-cmd ...

  5. HDOJ 3593 The most powerful force

    树形DP / 泛化物品的背包...可以去看09年徐持衡论文<浅谈几类背包问题> The most powerful force Time Limit: 16000/8000 MS (Jav ...

  6. linux 分区问题

    一.最简单的分区 仅分出根目录(/)和最简单的内存置换空间(swap)即可 以虚拟机的分区(20G)为例: 一般给/分15G来安装linux系统,512M给swap,另外的4G可以留下备用 二.复杂一 ...

  7. hdu.1226.超级密码(bfs)

    超级密码 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  8. 第24天 runtime

    面试时被问到一个问题,如何实现weak变量的自动置nil?当时也不知道. 今天在实现target-action模式时,如何调用SEL,刚开始只会PerformSelector,但不能传递多个参数,后来 ...

  9. webrtc第二篇 聊天室

    聊天室模型不一样考虑的问题也不一样 1.websocket文本聊天 * step1 : 向聊天室所有用户(不包括该用户自己)发送当前用户上线信息.客户端用户栏回添加此用户 * step2 : 将该用户 ...

  10. C语言的源程序字符集与执行字符集

    我们程序文件的字符集就是我们写出来的.c扩展名的文件的字符集,这里用的是系统默认的 ANSI 字符集,如下图: 上面的字符集我们不关心,我们关心的是 源程序的字符集 和程序的 执行字符集 ,源程序的字 ...