B1970 [Ahoi2005]Code 矿藏编码 暴力模拟
2024-08-31 05:52:04
小詹从哪整出来这么多水题?%%%这个题用栈模拟一下,然后直接暴力就行了。。。一开始还没想到,用的dfs,我太菜了。。。
题干:
Description
依次对每份进行编码,得S1,S2,S3,S4。该矿藏区的编码S为2S1S2S3S4。 例如上图中,矿藏区的编码为:2021010210001。 小联希望你能根据给定的编码统计出这片矿藏区一共有多少格子区域是平地。
Input
第一行有一个整数K,表示有矿藏区的规模为 (1 < K < 50)。第二行有一串编码,有0、1组成,长度不超过200,表示该矿藏区的编码。
Output
单行输出一个整数,表示矿藏区中一共有多少格子是平地。
Sample Input
2
2021010210001
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 ;
}
最新文章
- thinkPHP的用法之创建新项目
- clearInterval,setInterval,clearTimeout,setTimeout
- 每日英语:A Whiff Of &#39;Welcome Home&#39;
- C语言--通用类型栈
- Nodejs爬虫进阶教程之异步并发控制
- 2数组的slice和splice方法
- ActiveMQ源码架构解析第一节(转)
- 【iOS】UIViewController生命周期
- 算法-找出与目标数字相同的digit组成的整数中比该数字大的数集中的最小数字
- HTML5浏览器端图片预览&;生成Base64
- Numpy库的下载及安装(吐血总结)
- 如何运行vue项目
- CAS机制与自旋锁
- EXCEL记录
- MUI上传图片之选择相册和相机上传
- 微信小程序:首页设置方法(开发模式,使用模式)与其他相关设置
- SSM框架整合的其它方式
- Java图片比对
- 一、集合框架(HashMap和Hashtable的区别)
- 用Redis实现分布式锁 与 实现任务队列