H. Zebras and Ocelots

计蒜客重现赛题目链接-H. Zebras and Ocelots
The famous City Central Zoo houses just two creatures, Zebras and Ocelots. These magical creatures spend their time in a single, tall column, each standing atop the back of the creature below it. Whenever the zoo bell rings, the ocelot lowest in the pile turns into a zebra, and all zebras (if there are any) below that creature simultaneously turn into ocelots. If there is no ocelot in the pile when the bell tolls, then nothing happens. The zookeeper has been watching this interesting process for years. Today, suddenly, he begins to wonder how much longer this can go on. That is, given a pile of zebras and/or ocelots, how many times may the bell toll before there are no more ocelots?
Input
Input consists of a number N in the range 1 to 60, followed by N lines, each of which is a single character, either Z (for zebra) or O(for ocelot). These give the order of the creatures from top (first) to bottom (last).

Output
Output should be a single integer giving the number of times the bell must toll in order for there to be no more ocelots.
输出时每行末尾的多余空格,不影响答案正确性

样例输入1

3
Z
O
Z

样例输出1

2

样例输入2

4
O
Z
Z
O

样例输出2

9

题目大意

给出一个Z和O的序列,每次变化序列最后的O变成Z,后面的Z变成O,问需要多少次变化才能使该序列没有O全是Z

解题思路

找规律即可
倒数第i位的O把它变为Z所需的次数是2n-i
所以用快速幂就行

附上代码

#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
string s;
ll quick_pow(ll x,ll n){ll ans=1;while(n){if(n&1) ans*=x;x*=x;n>>=1;}return ans;
}
signed main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin>>n;ll ans=0;for(int i=n-1;i>=0;i--)cin>>s[i];for(int i=0;i<n;i++){if(s[i]=='O')ans+=quick_pow(2,i);}cout<<ans<<endl;return 0;
}

ICPC North Central NA Contest 2017 H.Zebras and Ocelots相关推荐

  1. ICPC North Central NA Contest 2017 计蒜客重现 解(补)题报告

    前言 不知不觉又到了周六训练赛,时间过得真快.手机前段时间被我不小心摔坏了,没手机玩的第十天, 无奈只能学习了 ,想它.题目还是要做的,题解还是要写的,CF还是得抽时间打的,所以说手机坏了貌似是好事. ...

  2. 2021年度训练联盟热身训练赛第二场(ICPC North Central NA Contest 2019,南阳师范学院),签到题ABCDEFGIJ

    A. Binarize It,简单枚举 链接:https://ac.nowcoder.com/acm/contest/12794/A 来源:牛客网 题目描述 Professor Boolando ca ...

  3. ICPC North America Qualifier Contest 2015 按通过率从 J开始

    J. Torn To Pieces 思路很简单,主要是怎么实现: #include <bits/stdc++.h> using namespace std; typedef long lo ...

  4. The 2019 ICPC Asia Shanghai Regional Contest

    The 2019 ICPC Asia Shanghai Regional Contest 题号 题目 知识点 A Mr. Panda and Dominoes B Prefix Code C Maze ...

  5. 2018 ICPC Asia Jakarta Regional Contest

    2018 ICPC Asia Jakarta Regional Contest 题号 题目 知识点 难度 A Edit Distance B Rotating Gear C Smart Thief D ...

  6. The 2021 ICPC Asia Regionals Online Contest (I)

    The 2021 ICPC Asia Regionals Online Contest (I) 写了一晚上,日- 文章目录 一. A Busiest Computing Nodes 二.D Edge ...

  7. The 2022 ICPC Asia Regionals Online Contest (I)

    D题 The 2022 ICPC Asia Regionals Online Contest (I) 03:14:13 H Step Debugging 作者 pku 单位 北京大学 Rikka is ...

  8. 2021 ICPC Southeastern Europe Regional Contest Werewolves(树上背包)

    2021 ICPC Southeastern Europe Regional Contest Werewolves(树上背包) 链接 题意:给出一个n个节点的树(n≤3000n\le3000n≤300 ...

  9. 【题目记录】——The 2021 ICPC Asia Jinan Regional Contest

    文章目录 C Optimal Strategy 组合数 H Game Coin K Search For Mafuyu 欧拉序列 题目集地址 The 2021 ICPC Asia Jinan Regi ...

  10. 2021 ICPC Southeastern Europe Regional Contest(更新至六题)

    2021 ICPC Southeastern Europe Regional Contest A题签到 A. King of String Comparison 题意:给两个字符串,找出有多少对(l, ...

最新文章

  1. 利用SIFt特征点和RANSAC方法进行物体识别(利用openCV和vs2010实现)
  2. linux命令之创建符号连接-ln
  3. 高 star 开源项目来实验楼啦,深度学习强推教材
  4. 大数据入门笔记(三)
  5. 【debug】moduleNotFoundError:No module named 'exceptions'
  6. java ajax json 乱码_java+ajax加载中文json串后出现乱码问题的解决办法
  7. 【OpenCV应用】python处理行李图像匹配项目——图像(简单)清晰化
  8. 广度优先遍历(Breadth First Search)
  9. 使用md5对文件去重
  10. ubuntu查看磁盘分区使用
  11. IE浏览器无法查看源文件的8大原因
  12. java星座出生日期_Java根据出生日期计算星座
  13. 录入姓名完成座位表,学习前端的小伙伴可以关注一波,用js+html+css构成
  14. 骡马盒子搭建详细教程
  15. 数学笔记27——极坐标下的面积
  16. Spark中repartition和coalesce的用法
  17. Excel批量一键切换英文字母大小写
  18. [BZOJ1616][Usaco2008 Mar]Cow Travelling游荡的奶牛(dfs||dp)
  19. 在家办公可摸鱼?屁,忙到怀疑人生!
  20. 槟城usm大学计算机专业怎么样,马来西亚理科大学USM比你想的好太多了!

热门文章

  1. vue+element_ui纯前端下载csv文件
  2. 在哪些场景下要使用CDN加速服务
  3. [GNN图神经网络]普通邻接矩阵和 Adjacency Matrix 与 COO稀疏矩阵(edge_index, 和edge_w)相互转化
  4. python爬取酷狗音乐top500及歌词_爬取酷狗音乐Top500(示例代码)
  5. VLN论文英语表达积累
  6. c语言密文加密解密问题注释,c语言通过openssl aes对称加解密和base64编解码将密码存储成密文...
  7. 《地球概论》(第3版)笔记 第四章 地球运动的地理意义
  8. 配置Dot1q终结子接口实现跨设备VLAN间通信示例
  9. 英语学习口诀大全be 的用法口诀
  10. eclipse,wtp配置