现在的位置: 首页 > 综合 > 正文

codeforces 284B Cows and Poker Game 思维问题

2014年01月11日 ⁄ 综合 ⁄ 共 1627字 ⁄ 字号 评论关闭
B. Cows and Poker Game
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Sample test(s)
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.

题意很简单。不是‘F’的人伸手,但是剩余的人中不能含有对应的状态‘A’和 ‘I’

直接用O(n)的算法就解决了,统计下 ‘I’和‘A’的个数,这样就可以来回答这个问题了。注意不相等的情况

分别讨论一下I和A的个数,要覆盖到各种情况。

#include<stdio.h>
#include<string.h>
char a[2000000],b[2000000];

int main()
{
   int len1,len2;
   while(scanf("%s",a)!=EOF){
      int f1=1,f2=1;
      scanf("%s",b);
      len1=strlen(a);
      len2=strlen(b);
      if(len1!=len2){printf("NO\n");continue;} //注意不相等的情况
      int i,sum=0;
      for(i=0;i<len1;i++){    //用f1和f2来统计A和I的个数
         if(a[i]=='1')sum++;
      }
      if(sum==0)f1=0;
      sum=0;
      for(i=0;i<len2;i++){
         if(b[i]=='1')sum++;
      }
      if(sum==0)f2=0;
     // printf("%d%d\n",f1,f2);
      if(f1==f2)printf("YES\n");
      else printf("NO\n");


   }

}

抱歉!评论已关闭.