codeforces 493A. Vasya and Football 解题报告
题目链接: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 解题报告的更多相关文章
- codeforces 460A Vasya and Socks 解题报告
题目链接:http://codeforces.com/problemset/problem/460/A 题目意思:有一个人有 n 对袜子,每天早上会穿一对,然后当天的晚上就会扔掉,不过他会在 m 的倍 ...
- codeforces 493B.Vasya and Wrestling 解题报告
题目链接:http://codeforces.com/problemset/problem/493/B 题目意思:给出 n 个 techniques,每个 technique 的值为 ai. ai & ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- codeforces B. Xenia and Ringroad 解题报告
题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...
- Codeforces Round #262 (Div. 2)解题报告
详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks http ...
随机推荐
- jQuery回调、递延对象总结(上篇)—— jQuery.Callbacks
前言: 作为参数传递给另一个函数执行的函数我们称为回调函数,那么该回调又是否是异步的呢,何谓异步,如:作为事件处理器,或作为参数传递给 (setTimeout,setInterval)这样的异步函数, ...
- Ruby学习之mixin
直接上代码: module Action def jump @distance = rand(4) + 2 puts "I jumped forward #{@distance} feet! ...
- C#爬虫之~苏飞万能框架使用教程
苏飞的框架帮助类,很多人应该都知道,不知道可以百度,此处直接说用法. //引入命名空间 using CsharpHttpHelper; //创建Httphelper对象 HttpHelper http ...
- .NET Core Preview
.NET Core Preview 这是很容易上手使用.NET Core在您选择的平台上. 你只需要一个命令行,一个文本编辑器和10分钟的时间. 原文链接:https://www.microsoft. ...
- Nginx初学者指南
Starting, Stopping, and Reloading Configuration To start nginx, run the executable file. Once nginx ...
- HDU 2222 AC自动机模板题
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...
- php字符串格式化函数addslashes()
1.这个函数的使用和php.ini中的magic_quotes_gpc的配置有关,默认情况下,这个配置为on.并且,这个配置处于一个较高级别,脚本中不能修改.所以,检测这个配置情况就很重要. 2.在脚 ...
- UOJ#35 —— 后缀排序
1.题目大意:后缀数组模板题 2.分析:汝佳的书上的代码的有bug,还有那个n是字符串长度+1,''也要加入排序的 存个模板QAQ #include <cstdio> #include & ...
- 关于Promise:你可能不知道的6件事
FROM ME : 文章介绍了6个Promise的知识点: 1.then() 返回一个 forked Promise(分叉的 Promise):返回的有两种情况: 2.回调函数应该传递结果:在 pro ...
- PyQt4关闭最大化最小化取消双击最大化
self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHi ...