3 C S F 2 S C 4 S S S SSample 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[1010]; set<char> book; map<char,int> list; int main() { //freopen("input.txt","r",stdin); int n; while(~scanf("%d",&n)){ int cnt=0; for(int i=0;i<n;i++){ cin>>a[i]; list[a[i]]++; book.insert(a[i]); } if(book.size()==1||book.size()==3) printf("%d\n",n); else if(book.size()==2) { if(list[‘C‘]!=0&&list[‘S‘]!=0) printf("%d\n",list[‘C‘]); else if(list[‘F‘]!=0&&list[‘S‘]!=0) printf("%d\n",list[‘S‘]); else if(list[‘C‘]!=0&&list[‘F‘]!=0) printf("%d\n",list[‘F‘]); } list.clear(); book.clear(); } return 0; }
poj-2232 New Stone-Forfex-Cloth Game 思维题
原文:https://www.cnblogs.com/cautx/p/11616742.html