hdu 4252 A Famous City
2012-07-21 23:14
267 查看
A Famous City
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 516 Accepted Submission(s): 212
[align=left]Problem Description[/align]
After Mr. B arrived in Warsaw, he was shocked by the skyscrapers and took several photos. But now when he looks at these photos, he finds in surprise that he isn't able to point out even the number of buildings in it. So he decides
to work it out as follows:
- divide the photo into n vertical pieces from left to right. The buildings in the photo can be treated as rectangles, the lower edge of which is the horizon. One building may span several consecutive pieces, but each piece can only contain one visible building,
or no buildings at all.
- measure the height of each building in that piece.
- write a program to calculate the minimum number of buildings.
Mr. B has finished the first two steps, the last comes to you.
[align=left]Input[/align]
Each test case starts with a line containing an integer n (1 <= n <= 100,000). Following this is a line containing n integers - the height of building in each piece respectively. Note that zero height means there are no buildings
in this piece at all. All the input numbers will be nonnegative and less than 1,000,000,000.
[align=left]Output[/align]
For each test case, display a single line containing the case number and the minimum possible number of buildings in the photo.
[align=left]Sample Input[/align]
3 1 2 3 3 1 2 1
[align=left]Sample Output[/align]
Case 1: 3 Case 2: 2 Hint The possible configurations of the samples are illustrated below:
[align=left]Source[/align]
Fudan Local Programming Contest 2012
题目大意是找到最少的建筑物数量。
要注意的当a[i]后面的数字比他小的时候直接跳出循环,因为有题意知,只要比它小,就会被挡住。
#include<iostream> #include<cstdio> #include<cstring> #define N 100010 using namespace std; int a ,visited ; int main() { int n,i,ans,j,cas=1; while(scanf("%d",&n)!=EOF) { ans=0; memset(visited,0,sizeof(visited)); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) if(visited[i]==0) { for(j=i+1;j<=n;j++) { if(a[i]==a[j]) visited[j]=1; else if(a[i]>a[j]) break; } } for(i=1;i<=n;i++) if(visited[i]==0&&a[i]!=0) ans++; printf("Case %d: %d\n",cas++,ans); } return 0; }
相关文章推荐
- HDU 4252 A Famous City
- HDU 4252 A Famous City
- HDU - 4252 A Famous City (单调栈)
- nyoj-140-A Famous City//hdu-4252-A Famous City
- HDU:4252 A Famous City(单调栈)
- [HDU 4252] A Famous City[单调队列]
- HDU/HDOJ----4252 A Famous City
- HDOJ 4252 A Famous City 单调栈
- HDOJ 4252 A Famous City 单调栈
- hdu A Famous City
- hdu 1505 dp City Game
- HDU 4496 D-City
- hdu 4496 D-City
- 【并查集】HDU 4496 D-City
- HDU 1347 Grandpa is Famous
- HDU 4252 A Famous City 解题报告
- HDU 4254 A Famous Game(概率与期望)
- HDU 4253 Two Famous Companies(最小生成树+二分)
- 【类多重背包+组合数】HDU 4248 A Famous Stone Collector
- HDU 1505 City Game