题目链接: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. 全屏背景:15个jQuery插件实现全屏背景图像或媒体

    动态网站通常利用背景图像或预加载屏幕,以保证所有资源都加载到页面上,在浏览器中充分呈现.现在很多网站都炫耀自己的图像作为背景图像全屏背景,追溯到旧的Flash网站却用自己的方式在HTML资源重布局. ...

  2. 一个漂亮的php验证码类(分享)

    直接上代码: 复制代码 代码如下: //验证码类class ValidateCode { private $charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRS ...

  3. HTML5+学习笔记2-------边看代码边研究貌似还是有点问题...还在研究中api中

    // 拍照 function getImage() { outSet( "开始拍照:" ); var cmr = plus.camera.getCamera(); cmr.capt ...

  4. [译]AngularJS中几种Providers(Factory, Service, Provider)的区别

    原文: http://blog.xebia.com/2013/09/01/differences-between-providers-in-angularjs/ 什么是Provider? Angula ...

  5. Elven Postman(BST )

    Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  6. 【PHP面向对象(OOP)编程入门教程】5.如何实例化对象?

    我们上面说过面向对象程序的单位就是对象,但对象又是通过类的实例化出来的,既然我们类会声明了,下一步就是实例化对象了. 当定义好类后,我们使用new关键字来生成一个对象. $对象名称 = new 类名称 ...

  7. ios 微博登录 21338错误 sso package or sign error

    os中,是你项目的bundle id 和 连接的微博开发账户里面的bundle id 不一致造成的. 特别是,你把你注册的appKey放到你下载的官方的demo里面测试,肯定会出现这种情况, 所以,你 ...

  8. C#调用java类、jar包方法

    一.将已经编译后的java中Class文件进行打包:打包命令JAR 如:将某目录下的所有class文件夹全部进行打包处理: 使用的命令:jar cvf test.jar -C com/ . 其中tes ...

  9. Android系统截屏的实现(附代码)

    1.背景                     写博客快两年了,写了100+的文章,最火的文章也是大家最关注的就是如何实现android系统截屏.其实我们google android_screen_ ...

  10. Android本地数据存储之SQLite关系型数据库 ——SQLiteDatabase

    数据库的创建,获取,执行sql语句: 框架搭建:dao 思考: 1.数据库保存在哪里? 2.如何创建数据库?如何创建表? 3.如何更新数据库?如何更改表的列数据? 4.如何获取数据库? 5.如何修改数 ...