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 任取一个点作为根节点,那么去掉这个 ...
随机推荐
- 安装yarn集群
安装yarn集群 # mapreduce运行平台YARN mapreduce程序应该是在很多机器上并行启动,而且先执行map task,当众多的maptask都处理完自己的数据 后,还需要启动众多的r ...
- Leetcode之二分法专题-167. 两数之和 II - 输入有序数组(Two Sum II - Input array is sorted)
Leetcode之二分法专题-167. 两数之和 II - 输入有序数组(Two Sum II - Input array is sorted) 给定一个已按照升序排列 的有序数组,找到两个数使得它们 ...
- Leetcode之深度优先搜索(DFS)专题-200. 岛屿数量(Number of Islands)
Leetcode之深度优先搜索(DFS)专题-200. 岛屿数量(Number of Islands) 深度优先搜索的解题详细介绍,点击 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计 ...
- MSIL实用指南-数据类型转换
一.类的强制转换1.转换成某个类用Castclass指令.实例代码:ilGenerator.Emit( OpCodes.Castclass , typeof(ClassA) ); 2.转换成某个值类型 ...
- Python--函数参数类型、用法及代码示例
在编程语言里,将一个个功能定义成函数,能够进行反复调用,而不是每次都重复相同的代码,这种方式能够大幅度降低代码的复杂度. 函数的好处: 1.代码重用 2.保持一致性 3.可扩展性 1.基础 我们定义函 ...
- H5调用相机和相册更换头像
需求:H5调用手机的相机和相册从而实现更换头像的功能 这个功能是很常用的一个功能,因此做一个记录. 1.在头像img下加一个文件输入框 <input type="file" ...
- Gson的解析Json数据的两种方式
转载:https://blog.csdn.net/huplion/article/details/78984977 在线JSON字符串转Java实体类(JavaBean.Entity): https: ...
- c#搭建webapi项目
一.添加WebApi项目 二.nuget下载WebApi所需的类库引用 install-package Microsoft.AspNet.WebApi install-package Micr ...
- HDU 1173 采矿
采矿 题解:如果给你一条线段(左右端点设为A,B), 那么在这条线上的任意一点到A B距离之和是一个定值, 然后如果再这条线段内在任意确定一个定点C, 那么这条线段上再任意取一个点,这个点到 A B ...
- 每天学会一点点(spring-mvc.xml与web.xml配置文件)
1.spring-mvc.xml中拦截器的使用 首先在springMVC.xml配置如下代码: <!-- 拦截器 --> <mvc:interceptors> <bean ...