poj-2232 New Stone-Forfex-Cloth Game 思维题
In this game, a number of children sit in a circle, each one
shows a gesture (one of the Stone, the Forfex and the Cloth), which
can't be changed in the whole game. Then a randomly chosen child (we
call him player A) compares his gesture with the one on his
anticlockwise (we call him play B) direction. And the loser should jump
out of the circle. This operation continues until there is only one
child left, which is the winner. Of course the winner is decided by both
the gestures the children show and the order to compare. Your task is
to tell the total number of possible winners.
The game obeys the following rulers:
1. Forfex beat Cloth.
2. Cloth beat Stone.
3. Stone beat Forfex.
4. If it is a draw, play A wins.
Input
line contains an integer N (the number of children, 1 <= N <=
1000), and the second line contains N capitals including 'S', 'F' and
'C, which are separated by a single space and represent the gestures of N
children in clockwise order. Here 'S' expresses the Stone, 'F'
expresses the Forfex, and 'C' expresses the Cloth.
Output
Sample Input
3
C S F
2
S C
4
S S S S
Sample Output
3
1
4
poj-2232;Caution_X;20191002;规律;-
description modelling:n个人围成一圈玩石头剪刀布,任选一人开始,逆时再任选一人玩石头剪刀布,输的人出圈,问最后留下的人有多少种情况;-
major steps to solve it:;-
考虑三种情况:;-
(1)所有人只出一个手势,那么任意一个人都有可能留下,答案为n;-
(2)所有人只出两种手势,虽然对手是任意挑选的,但是赢的人的手势是确定的,所以留下的人只能是出了能赢手势的人,此时答案为出了赢得手势的人的人数;-
(3)三种手势都有,显然任意一种手势,只要合理安排对手就一定能赢,所以此时答案还是n;-
warnings:A挑了B当对手,两人出相同手势,A赢;.
AC CODE:
#include<iostream>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
char a[];
set<char> book;
map<char,int> list;
int main()
{
//freopen("input.txt","r",stdin);
int n;
while(~scanf("%d",&n)){
int cnt=;
for(int i=;i<n;i++){
cin>>a[i];
list[a[i]]++;
book.insert(a[i]);
}
if(book.size()==||book.size()==) printf("%d\n",n);
else if(book.size()==) {
if(list['C']!=&&list['S']!=) printf("%d\n",list['C']);
else if(list['F']!=&&list['S']!=) printf("%d\n",list['S']);
else if(list['C']!=&&list['F']!=) printf("%d\n",list['F']);
}
list.clear();
book.clear();
}
return ;
}
poj-2232 New Stone-Forfex-Cloth Game 思维题的更多相关文章
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...
- [NOIP2005] 过河【Dp,思维题,缩点】
Online Judge:Luogu P1052 Label:Dp,思维题,缩点,数学 题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子 ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...
- cf796c 树形,思维题
一开始以为是个树形dp,特地去学了..结果是个思维题 /* 树结构,设最大点权值为Max,则答案必在在区间[Max,Max+2] 证明ans <= Max+2 任取一个点作为根节点,那么去掉这个 ...
随机推荐
- Codeforces 975D
题意略. 思路:我们来写一下公式: P1:(x1 + t * Vx1,y1 + t * Vy1) P2:(x2 + t * Vx2,y2 + t * Vy2) x1 + ...
- JUC包实现的同步机制,原理以及简单用法总结
除了用Synchronized关键字修饰同步块,让线程获取某对象的锁实现多线程操作共享变量的同步外,还可以使用java.util.concurrent包.并且,juc包机制下的同步更灵活.juc包的所 ...
- Keras(七)Keras.layers各种层介绍
一.网络层 keras的层主要包括: 常用层(Core).卷积层(Convolutional).池化层(Pooling).局部连接层.递归层(Recurrent).嵌入层( Embedding).高级 ...
- 矩阵之间无循环计算L2距离
实现两个矩阵的无循环计算欧氏距离 Euclidean distance navigation: 1.问题描述 2.解决方法 1.问题来源 kNN算法中会计算两个矩阵的距离 可以使用循环的方法来实现,效 ...
- CF1025C Plasticine zebra 思维 字符串
Plasticine zebra time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CF982C Cut 'em all! DFS 树 * 二十一
Cut 'em all! time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Oracle sqlldr 在DOS窗口导入多列数据到数据库表
sqlldr 用法详见:https://www.cnblogs.com/rootq/archive/2009/03/01/1401061.html 测试内容: 1.创建数据库表: create tab ...
- Storm VS Flink ——性能对比
1.背景 Apache Flink 和 Apache Storm 是当前业界广泛使用的两个分布式实时计算框架.其中 Apache Storm(以下简称"Storm")在美团点评实时 ...
- 那些年,我们误解的 JavaScript 闭包
说到闭包,大部分的初始者,都是谈虎色变的.最近对闭包,有了自己的理解,就感觉.其实我们误解闭包.也被网上各种说的闭包的解释给搞迷糊. 一句话:要想理解一个东西还是看权威的东西. 下面我来通俗的讲解一个 ...
- Java中Jedis连接Linux上的Redis出现connect time out(解决方案)
我的代码: /** * * <p>Title: testJedis</p> * <p>Description: 测试单机版的redis连接(每连接一次构建一个对象) ...