B - Cows and Poker Game
Problem description
There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any betting decisions, he/she may only do so if all other players have a status of either "ALLIN" or "FOLDED". The player's own status may be either "ALLIN" or "IN".
Find the number of cows that can currently show their hands without affecting any betting decisions.
Input
The first line contains a single integer, n (2 ≤ n ≤ 2·105). The second line contains n characters, each either "A", "I", or "F". The i-th character is "A" if the i-th player's status is "ALLIN", "I" if the i-th player's status is "IN", or "F" if the i-th player's status is "FOLDED".
Output
The first line should contain a single integer denoting the number of players that can currently show their hands.
Examples
Input
6
AFFAAA
Output
4
Input
3
AFI
Output
1
Note
In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand.
解题思路:每个玩家有两种状态:"ALLIN"或者"IN";只要当前玩家的状态不是"FOLDED",并且其他玩家的状态是"ALLIN"或者"FOLDED",那么当前玩家就可以将他的手放在桌子上,求将手放在桌子上的一共有几个玩家。做法:假设字符'A','F','I'出现的次数依次为a,f,i:①如果i==0,则字符串中只有'A'或'F',即将手放在桌子上的玩家人数为a;②如果i==1,当且仅当某位玩家的状态为"IN",则其他玩家的状态必定是'A'或者'F',即该玩家可以将手放在桌子上,人数为1;③如果i>1,则不满足条件,必定没有玩家的手放在桌子上,人数为0。
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
int n,a=,f=,i=;char s[maxn];
int main(){
cin>>n;getchar();
cin>>s;
for(int j=;j<n;++j){
if(s[j]=='A')a++;
else if(s[j]=='F')f++;
else i++;
}
if(i==)cout<<a<<endl;//如果没有I,则直接输出A的个数
else if(i==)cout<<<<endl;//i==1时,其他只有A或F,则此时只有一个人的手放在桌上
else cout<<<<endl;//否则不满足条件即为0个
return ;
}
B - Cows and Poker Game的更多相关文章
- Codeforces Round #174 (Div. 2)
A. Cows and Primitive Roots 暴力. B. Cows and Poker Game 模拟. C. Cows and Sequence 线段树维护. D. Cow Progra ...
- Codeforces Round #174 (Div. 1 + Div. 2)
A. Cows and Primitive Roots 暴力. B. Cows and Poker Game 模拟. C. Cows and Sequence 线段树维护. D. Cow Progra ...
- 洛谷P3078 [USACO13MAR]扑克牌型Poker Hands
题目描述 Bessie and her friends are playing a unique version of poker involving a deck with \(N\) (\(1 \ ...
- P3078 [USACO13MAR]扑克牌型Poker Hands
题目描述 Bessie and her friends are playing a unique version of poker involving a deck with N (1 <= N ...
- 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands
看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...
- 洛谷 P3078 [USACO13MAR]扑克牌型Poker Hands
P3078 [USACO13MAR]扑克牌型Poker Hands 题目描述 Bessie and her friends are playing a unique version of poker ...
- USACO Poker Hands
洛谷 P3078 [USACO13MAR]扑克牌型Poker Hands 题目传送门 JDOJ 2359: USACO 2013 Mar Silver 1.Poker Hands JDOJ传送门 题目 ...
- [LeetCode] Bulls and Cows 公母牛游戏
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
- POJ 2186 Popular Cows(Targin缩点)
传送门 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31808 Accepted: 1292 ...
随机推荐
- vue中fetch请求
1. 请求方式:get 请求参数:menuName 返回的结果:data created(){ this._initPageData() }, methods:{ _initPageData(){ f ...
- yum仓库配置ftpx协议
[root@localhost ~]# iptables -F[root@localhost ~]# systemctl stop firewalld[root@localhost ~]# syste ...
- 57 和为S的数字
题目一:和为S的两个数字 输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测试案例,输出两个数,小 ...
- 非递归全排列 python实现
python algorithm 全排列(Permutation) 排列(英语:Permutation)是将相异物件或符号根据确定的顺序重排.每个顺序都称作一个排列.例如,从一到六的数字有720种排列 ...
- 在Python脚本中调用Django环境(方便、右键运行,可用于ORM测试)
随便创建一个py文件即可: import os if __name__ == '__main__': os.environ.setdefault("DJANGO_SETTINGS_MODUL ...
- linux获得网卡信息
#define MAX_INTERFACE 64 int showifs() { int i; int rc; int sock; int ifnum; struct ifreq ifr[MAX_IN ...
- ES6-babel转码
关于BaBel转码 有人问我babel的功能以及执行的过程和配置,在网上查阅了大量的资料~收集到这些~有错请指出,及时修改. ------------------------------------- ...
- hadoop2.3.0cdh5.0.2 升级到cdh5.7.0
后儿就放假了,上班这心真心收不住,为了能充实的度过这难熬的两天,我决定搞个大工程.....ps:我为啥这么期待放假呢,在沙发上像死人一样躺一天真的有意义嘛....... 当然版本:hadoop2.3. ...
- Mysql中文乱码以及导出为sql语句和Excel问题解决
Mysql中文乱码以及导出为sql语句和Excel问题解决 这几天基于Heritrix写了一个爬虫,用到mysql,在导入导出数据时,遇到一些乱码问题,好不容易解决了,记录一下,以备查看.一.导出数据 ...
- mode-c++
/*感谢机房JYW的友情馈赠*/#include <iostream> #include <cstdio> #include <cstring> #include ...