题目链接: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. 导航菜单:jQuery粘性滚动导航栏效果

    粘性滚动是当导航在滚动过程中会占粘于浏览器上,达到方便网站页面浏览的效果,也是一种用户体验,下面我们看一下是怎么实现的: jQuery的 smint插件,也是一个导航菜单固定插件.当页滚动时,导航菜单 ...

  2. SAMBA 共享服务器搭建

    yum install samba service smb start chkconfig smb on 1.给要共享的文件夹赋权限 777 2.修改 smb 的配置文件:/etc/samba/smb ...

  3. Form表单中method为get和post的区别

    序,form表单中的方法分为get和post,但你都知道他们之间的区别吗? Form表单中method为get和post的区别: 例子如下,有个Form表单. <form action=&quo ...

  4. Alice and Bob 要用到辗转相减

    Alice and BobTime Limit: 1 Sec  Memory Limit: 64 MBSubmit: 255  Solved: 43 Description Alice is a be ...

  5. 【C语言入门教程】1.1 基本程序结构

    基本程序结构就是从上至下顺序执行的程序,C语言程序必须有且只有一个主函数,程序从主函数开始执行,直到主函数结束.下例是根据半径求圆形面积的程序源代码. #include <stdio.h> ...

  6. 软件测试-----Graph Coverage作业

    /******************************************************* * Finds and prints n prime integers * Jeff ...

  7. sql查询比较两表不同数据与相同数据

    以下举例是查询相同数据,否则则相反 方法一: select * from A as x,B as y where x.a1=y.b1 and x.a2=y.b2 and x.a3=y.b3 方法二: ...

  8. oracle 行列转换的运用

    问题: 员工表: A(E_ID,NAME,) 部门表:  B(D_ID,D_NAME) 员工与部门关系:C(ID,E_ID,D_ID) SELECT  A.E_ID,A.NAME ,B.D_NAME ...

  9. BZOJ4196——noi2015软件包管理器

    1.题目大意:讲道理,就是让你有两个修改一个是把一个点到根的路径上的点权值全部变成1,另一个是把一个子树全部变成0 然后让你输出每次修改,改变的哪些节点的值 2.分析:就是一个树剖,树剖是满足dfs序 ...

  10. C++ const用法 尽可能使用const [转载]

    C++ const 允许指定一个语义约束,编译器会强制实施这个约束,允许程序员告诉编译器某值是保持不变的.如果在编程中确实有某个值保持不变,就应该明确使用const,这样可以获得编译器的帮助. 1.c ...