ALDS1_3_D: Areas on the Cross-Section Diagram
来源:互联网 发布:天猫跟淘宝的区别 编辑:程序博客网 时间:2024/05/08 15:00
ALDS1_3_D: Areas on the Cross-Section Diagram
题目摘要
计算积水的面积。
输入
1行,用”\”和”/”表示斜面,用”_”表示平地。
输出
第1行输出总面积,第2行输出积水数量和各积水处的横截面积。
#include<iostream>#include<stack>#include<vector>#include<string>#include<algorithm>using namespace std;int main(){ stack<int> S1; //储存"\" stack<pair<int,int>> S2; //(该积水处最左侧"\"的位置,该积水处当前的面积) char ch; int sum=0; //总面积 for(int i=0;cin>>ch;i++) { if(ch=='\\')S1.push(i); else if(ch=='/'&&S1.size()>0) { int j=S1.top();S1.pop(); sum+=i-j; int a=i-j; while(S2.size()>0&&S2.top().first>j) { a+=S2.top().second; S2.pop(); } //如果当前的"\"不是最左侧的,说明这对"\"和"/"已经和之前的积水处一起形成了一个更大的积水处。 S2.push(make_pair(j,a)); } } vector<int> ans; while(S2.size()>0) { ans.push_back(S2.top().second);S2.pop(); } reverse(ans.begin(),ans.end()); cout<<sum<<endl; cout<<ans.size(); for(int i=0;i<ans.size();i++) { cout<<" "; cout<<ans[i]; } cout<<endl; //输出}
0 0
- ALDS1_3_D: Areas on the Cross-Section Diagram
- ALDS1_3_D: Areas on the Cross-Section Diagram
- 第四章 ALDS1_3_D:Areas on the Cross-Section Diagram
- Areas on the Cross-Section Diagram
- Section 3.3 Home on the Range
- USACO Section 3.3 Home on the Range
- arm-linux-gcc compile the cross-platform mpich2 on ubuntu
- On the Android ListView listSelector to solve cross-border issues
- The Cross
- usaco Chapter 3 section 3.3 Home on the Range
- USACO Section 3.3 Home on the Range - 优化的BFS..
- USACO-Section 3.3-PROB Home on the Range
- 解决方法!:getImageData on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
- hdu3669 Cross the Wall
- Cross the Wall UVALive
- Clustering of residential areas based on residential conditions
- About the Use case diagram
- UML basics: The class diagram
- TangYuan使用教程-功能介绍
- TangYuan使用教程-XML介绍
- 我对Spring中<bean>的理解
- Doxygen初学与简单应用
- java数据类型
- ALDS1_3_D: Areas on the Cross-Section Diagram
- TangYuan使用教程-数据源
- 使用CSDN-markdown编辑器需要掌握的知识
- Handler 原理
- 创业公司成长记<二>
- C语言中,malloc和free深入理解
- A^T相关的计算
- 第十四周项目1---验证算法
- 小米5更新后android studio 通过USB安装报错:install_canceled_by_user