小詹从哪整出来这么多水题?%%%这个题用栈模拟一下,然后直接暴力就行了。。。一开始还没想到,用的dfs,我太菜了。。。

题干:

Description

依次对每份进行编码,得S1,S2,S3,S4。该矿藏区的编码S为2S1S2S3S4。 例如上图中,矿藏区的编码为:2021010210001。 小联希望你能根据给定的编码统计出这片矿藏区一共有多少格子区域是平地。

Input

第一行有一个整数K,表示有矿藏区的规模为 (1 < K < 50)。第二行有一串编码,有0、1组成,长度不超过200,表示该矿藏区的编码。

Output

单行输出一个整数,表示矿藏区中一共有多少格子是平地。

Sample Input

2
2021010210001

Sample Output

9

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
double tot = ;
int k,l;
stack <int> st;
char s[];
int main()
{
read(k);
scanf("%s",s + );
l = strlen(s + );
st.push(k);
duke(i,,l)
{
int t = st.top();st.pop();
if(s[i] == '')
{
duke(j,,)
{
st.push(t - );
// i++;
}
}
if(s[i] == '')
{
// cout<<t<<endl;
tot += pow(,t) * pow(,t);
}
// cout<<i<<endl;
}
printf("%.0lf\n",tot);
return ;
}

最新文章

  1. thinkPHP的用法之创建新项目
  2. clearInterval,setInterval,clearTimeout,setTimeout
  3. 每日英语:A Whiff Of &#39;Welcome Home&#39;
  4. C语言--通用类型栈
  5. Nodejs爬虫进阶教程之异步并发控制
  6. 2数组的slice和splice方法
  7. ActiveMQ源码架构解析第一节(转)
  8. 【iOS】UIViewController生命周期
  9. 算法-找出与目标数字相同的digit组成的整数中比该数字大的数集中的最小数字
  10. HTML5浏览器端图片预览&amp;生成Base64
  11. Numpy库的下载及安装(吐血总结)
  12. 如何运行vue项目
  13. CAS机制与自旋锁
  14. EXCEL记录
  15. MUI上传图片之选择相册和相机上传
  16. 微信小程序:首页设置方法(开发模式,使用模式)与其他相关设置
  17. SSM框架整合的其它方式
  18. Java图片比对
  19. 一、集合框架(HashMap和Hashtable的区别)
  20. 用Redis实现分布式锁 与 实现任务队列

热门文章

  1. 输出字符串格式化/ Linq对数组操作 /一个按钮样式
  2. vue中引入json数据,不用本地请求
  3. PAT_A1126#Eulerian Path
  4. 01 c++常见面试题总结
  5. 2.6、Flask扩展
  6. Linux—Ubuntu14.0.5安装MySQL
  7. docker安装部署
  8. IE下自定义错误页面不显示的原因
  9. 【codeforces 793C】Mice problem
  10. lucene_02_IKAnalyre