Codeforces Round #281 (Div. 2) A. Vasya and Football
来源:互联网 发布:软件的收费模式 编辑:程序博客网 时间:2024/05/16 07:47
我深夜打开电脑,本来想水一道水题就睡觉,没想到水题也没过……
其实题目很简单。先给两个足球队名(不超过20个字符),接着给出犯规次数n。接下来的n行是犯规的细节,分别是{多少分钟,主场h/客场a,球员号,黄牌y/红牌r}。请你输出球员第一次收到红牌的情况,分别是{球队名,球员号,时间}。
直接上代码……
#include<bits/stdc++.h>using namespace std;struct Player{ char tm; int no; bool operator<(const Player& p) const{ if(p.tm==tm) return no<p.no; else return p.tm<tm; }};int main(){ char hName[24],aName[24]; scanf("%s%s",hName,aName); int fouls; scanf("%d",&fouls); map<Player,int> cnt; map<Player,bool> rcd; while(fouls--){ int minute,playerNumber; char team,card; scanf("%d %c %d %c",&minute,&team,&playerNumber,&card); Player p; p.tm=team; p.no=playerNumber; if(card=='y') cnt[p]++; else cnt[p]+=2; if(cnt[p]>=2 && rcd[p]==false){ printf("%s %d %d\n",p.tm=='h'?hName:aName,playerNumber,minute); rcd[p]=true; } } return 0;}但是,对于渣渣每个水题背后都有伤心的故事。不仅是WA,更是本地都调不通!
首先,因为我使用了结构体Player,而且把结构体作为map的key使用,”map中的key默认是以less<>升序对元素排序(排序准则也可以修改),也就是说key必须具备operator<对元素排序,而平常我们的用的基本上都是基本类型元素作为key,所以就不存在这个问题了”(引用自http://www.cppblog.com/Apan/articles/75267.html点击打开链接)。开始我不知道这点,所以一直编译不通过。
后来编译通过了,输入又出问题。因为开始我这样写的
scanf("%d%c%d%c",&minute,&team,&playerNumber,&card);今早看了别人的代码才明白过来,晚上太糊涂了,这里面涉及字符输入,所以不能直接把几个%连着,这样空格会读到字符变量里去。
接下submit了,发现在开始的几个数据就挂了。因为开始我的输出条件是
if(cnt[p]==2) printf("%s %d %d\n",p.tm=='h'?hName:aName,playerNumber,minute);但是数据有的是同一个队员接连或黄牌、红牌(或者反过来),甚至连续两个红牌(说好的红牌就罚下场呢!!不过本题里确实没说)。这样就不得不把判断条件改为上面完整代码里那样。参考了一下其他人的代码,他们也有这样写的,即把黄牌、红牌表示为计数。只不过他们的内存使用很小,因为他们没用STL map,而是直接用二维数组做的。
0 0
- Codeforces Round #281 (Div. 2) A. Vasya and Football
- Codeforces Round #281 (Div. 2) A - Vasya and Football
- #281 (div.2) A.Vasya and football
- Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
- Codeforces Round #262 (Div. 2) A. Vasya and Socks
- Codeforces Round #281 (Div. 2)-D. Vasya and Chess
- Codeforces 493A. Vasya and Football 水
- Codeforces 493A Vasya and Football(水)
- CodeForces-493A.Vasya and Football
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball&D. Vasya and Chess
- Codeforces Round #206 (Div. 1) A. Vasya and Robot
- A. Vasya and Football
- A Vasya and Football
- A. Vasya and Football
- Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)
- 【Codeforces Round 262 (Div 2)A】【水题】Vasya and Socks 妈妈买袜子 最多穿几天
- Codeforces Round #206 (Div. 2) C - Vasya and Robot
- Codeforces Round #206 (Div. 2) B. Vasya and Public Transport
- Firefox Crash后session内容的恢复
- deque
- 使用freemarker导出word
- java中格式化输出大神Formatter简历
- java的String的equals方法和"=="比较
- Codeforces Round #281 (Div. 2) A. Vasya and Football
- 简单的数据库输入和显示
- test11
- ACM计算几何题目推荐
- The Swift Programming Language--语言指南--反初始化
- 【LeetCode】Single Number
- rubymine license
- Delphi xe6 andriod 编程入门教程demo随书光盘
- c#将Excel数据导入到数据库的实现代码