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 ...
随机推荐
- 安装好Android Studio(如果内存足够可以改下as的内存)
找到studio的bin目录,找到如下文件
- PHP支付宝接口RSA验证
这两天一直困扰的PHP RSA签名验证问题终于解决了,由于之前RSA接触的不多,再加上官方至今还未有PHP的SDK可供参考,因此走了一些弯路,写在这里和大家分享. 虽然支付宝官方还未提供相关SD ...
- Python-Matplotlib安装及简单使用
在使用NumPy进行学习统计计算时是枯燥的,大量的数据令我们很头疼,所以我们需要把它图形化显示. Matplotlib是一个Python的图形框架,类似于MATLAB和R语言. Matplotlib的 ...
- linux 下安装tomcat
1.把安装包放到 tomcat的目录, 2.然后 解压 tar -zxvf apache-tomcat-7.0.70.tar.gz 解压. 3.然后启动tomcat
- Codeforces 260 C. Boredom
题目链接:http://codeforces.com/contest/456/problem/C 解题报告:给出一个序列,然后选择其中的一个数 k 删除,删除的同时要把k - 1和k + 1也删除掉, ...
- 网页中的CSS换行控制
在进行DivCSS布局时,需要对文本进行控制,向大家介绍一下,CSS中控制换行的四种属性.一.white-space 可以实现HTML中PRE标签的效果,以及单元格的noWrap效果.语法: whit ...
- hiho #1114 : 小Hi小Ho的惊天大作战:扫雷·一
#1114 : 小Hi小Ho的惊天大作战:扫雷·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 故事背景:密室.监视器与充满危机的广场 “我们还是循序渐进,先来考虑这 ...
- am335x 虚拟机环境变量的设置及注释
我用的还是老的Linux3.2.0的内核,只是借用了TI am335x SDK 3.0里面的工具. 首先下载TI官方的SDK,上一章已经安装了一个Ubuntu14.04的虚拟机. TI 最新的SDK下 ...
- BZOJ 2685: Sgu385 highlander
Sol 期望DP. \(f[i][j][k]\) 表示已经确定了 \(i\) 个点, 最大环大小为 \(j\) ,个数为 \(k\) 的方案数. 转移非常复杂,因为细节特别多. \(f[i][j][1 ...
- POJ 3281 网络流dinic算法
B - Dining Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...