Areas on the Cross-Section Diagram  Aizu - ALDS1_3_D

Areas on the Cross-Section Diagram

地域の治水対策として、洪水の被害状況をシミュレーションで仮想してみよう。

図のように $1 \times 1 (m^2)$ の区画からなる格子上に表された地域の模式断面図が与えられるので、地域にできる各水たまりの面積を報告してください。

与えられた地域に対して限りなく雨が降り、地域から溢れ出た水は左右の海に流れ出ると仮定します。 例えば、図の断面図では、左から面積が 4、2、1、19、9 の水たまりができます。

入力

模式断面図における斜面を '/' と '\'、平地を '_' で表した文字列が1行に与えられます。例えば、図の模式断面図は文字列
\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ で与えられます。

出力

次の形式で水たまりの面積を出力してください。

$A$
$k$ $L_1$ $L_2$ ... $L_k$

1行目に地域にできる水たまりの総面積を表す整数 $A$ を出力してください。

2行目に水たまりの数 $k$、各水たまりの面積 $L_i (i = 1, 2, ..., k)$ を断面図の左から順番に空白区切りで出力してください。

制約

  • $1 \leq 文字列の長さ \leq 20,000$

ただし、得点の 50 点分は以下の条件を満たす。

  • 水たまりの数は1つ以下であり ($k \leq 1$)、かつ文字列の長さは 100 以下である。

入力例 1

\\//

出力例 1

4
1 4

入力例 2

\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\

出力例 2

35
5 4 2 1 19 9

Note

题目分析:

本题是一道对栈的应用比较好的一道题,不仅运用栈的特性解决了水坑的左右匹配问题,还将他们分开储存,也仅仅只是运用一个下标判断和栈的特性。

代码如下:

     #include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std; int main(){
stack<int> S1;
stack<pair<int, int> > S2;
char ch;
int sum = ;
for(int i = ;cin >> ch; i++){
if(ch == '\\')S1.push(i);
else if(ch == '/' && S1.size() > ){
int j = S1.top();S1.pop();
sum += i - j;
int a = i - j;
while(S2.size() > && S2.top().first > j){
a += S2.top().second;S2.pop();
}
S2.push(make_pair(j, a));
}
}
vector<int> ans;
while(S2.size() > ){ans.push_back(S2.top().second);S2.pop();}
reverse(ans.begin(),ans.end());
cout<< sum << endl;
cout<< ans.size();
for( int i = ; i < ans.size(); i++){
cout<< " ";
cout<< ans[i];
}
cout << endl;
return ;
}

Areas on the Cross-Section Diagram的更多相关文章

  1. Transistor 晶体管 场效应 双极型 达林顿 CMOS PMOS BJT FET

    Transistor Tutorial Summary Transistor Tutorial Summary Bipolar Junction Transistor Tutorial We can ...

  2. Circles and Pi

    Circles and Pi Introduction id: intro-1 For as long as human beings exist, we have looked to the sky ...

  3. Video processing systems and methods

    BACKGROUND The present invention relates to video processing systems. Advances in imaging technology ...

  4. Computer Generated Angular Fisheye Projections [转]

    Computer GeneratedAngular Fisheye Projections Written by Paul Bourke May 2001 There are two main ide ...

  5. 每日英语:Risk-Averse Culture Infects U.S. Workers, Entrepreneurs

    Americans have long taken pride on their willingness to bet it all on a dream. But that risk-taking ...

  6. linux heads分析(转)

    内核默认的运行地址为PHY_OFFSET+0x8000,即物理地址开始后的0x8000字节处,前面是留给参数用的.参数以atag方式存储,默认放在0x100偏移位置. http://blog.chin ...

  7. BC in fluent

    Boundary conditions in Fluent Table of Contents 1. Boundary Conditions (BC) 1.1. Turbulence Paramete ...

  8. HEC-ResSim原文档

              HEC-ResSim Reservoir System Simulation             User's Manual       Version 3.1 May 201 ...

  9. STA之RC Corner再论

    Q:RC-Corner跟PVT怎么组合? A:通常的组合:   Q:通常说的ttcorner指的是啥? A:@孟时光 ttcorner是指管子在tt+RCtyp吧. Typesof corners W ...

  10. 使用Cadence绘制PCB流程

    转载:https://blog.csdn.net/hailin0716/article/details/47169799 之前使用过cadence画过几块板子,一直没有做过整理.每次画图遇到问题时,都 ...

随机推荐

  1. linux下实现在程序运行时的函数替换(热补丁)

    声明:以下的代码成果,是参考了网上的injso技术,在本文的最后会给出地址,同时非常感谢injso技术原作者的分享. 但是injso文章中的代码存在一些问题,所以后面出现的代码是经过作者修改和检测的. ...

  2. Computer Vision: OpenCV, Feature Tracking, and Beyond--From <<Make Things See>> by Greg

    In the 1960s, the legendary Stanford artificial intelligence pioneer, John McCarthy, famously gave a ...

  3. thinkphp3.2.3之自动完成的实现

    有时候,我们希望系统能够帮我们自动完成一些功能,比如自动为密码加密,忽略空等,这个时候我们就需要利用到自动完成(填写)的功能. ThinkPHP 模型层提供的数据处理方法,主要用于数据的自动处理和过滤 ...

  4. 欢迎加入threejs

    Threejs is the coolest graphics rendering engine I have ever seen, so what is threejs, Now, we have ...

  5. 可以正确显示表格线的Grid item view

    Android上要显示一个表格,没有Swing那么专门的JTable可用. 搜了下,一般用GridView,有诸多不便和需要自己实现的地方: 跟ListView一样的Adapter,getView的时 ...

  6. ID属性值为小数

    获取带有.的id值 <h1 id="123.45">dom对象</h1> <script> $('#123\\.45').attr('id') ...

  7. Spring MVC+FreeMarker简介

    最近做项目,刚接触到SpringMVC与FreeMarker框架,就简单介绍一下自己的理解,不正确的地方请大家指教!! 1.Spring MVC工作原理: 用户发送请求--->前端服务器去找相对 ...

  8. java23

    1:多线程(理解)    (1)多线程:一个应用程序有多条执行路径        进程:正在执行的应用程序        线程:进程的执行单元,执行路径        单线程:一个应用程序只有一条执行 ...

  9. 分享一些不错的sql语句

    1.说明:复制表(只复制结构,源表名:a   新表名:b)   (Access可用)  法一:select   *   into   b   from   a   where   1 <> ...

  10. python os.path

    os.path 提供了一些处理文件路径的函数. os.path.abspath(path) 返回绝对路径, 在大多数平台上, os.path.abspath(path) == os.path.norm ...