国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

HDU4252:A Famous City

2019-11-08 02:15:37
字體:
來源:轉載
供稿:網友
PRoblem DescriptionAfter 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. InputEach 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. OutputFor each test case, display a single line containing the case number and the minimum possible number of buildings in the photo. Sample Input
31 2 331 2 1 Sample Output
Case 1: 3Case 2: 2HintThe possible configurations of the samples are illustrated below:
題意:利用題目中給定的規律尋找到最少建筑的數量。弄懂題意很重要......數據范圍不大,可以暴力試一試。建筑的最大可能是總數減去0高度的,則答案就是最大可能減去重復的建筑。從開始遍歷,如果當前建筑低于前一個建筑,則遍歷位于當前建筑前面的建筑,看是否有與其相等的。若當前建筑高于前一個建筑,說明當前建筑是單獨的,繼續遍歷下一個建筑。具體看代碼。AC代碼:
#include <stdio.h>  #include <string.h>  #include <algorithm>  using namespace std;    int a[1000005],x,len;    int main()  {      int n,i,cas = 1,ans,j;      while(~scanf("%d",&n))      {          ans = 0;          for(i = 0; i<n; i++)              scanf("%d",&a[i]);          if(a[0]==0)              ans++;          for(i = 1; i<n; i++)          {              if(a[i]==0)                  ans++;  0高度建筑            else              {                  for(j = i-1; j>=0; j--)                  {                      if(a[i]>a[j])                          break;                      else if(a[i]==a[j])  建筑重復的情況                    {                          ans++;                          break;                      }                  }              }          }          printf("Case %d: %d/n",cas++,n-ans); ans包括 0高度建筑與重復建筑    }        return 0;  }  
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东源县| 泸溪县| 东明县| 黄骅市| 合水县| 马尔康县| 香河县| 滦南县| 军事| 家居| 凌源市| 黎川县| 微山县| 南乐县| 鹤壁市| 石屏县| 黑水县| 西乌珠穆沁旗| 宁津县| 和龙市| 乌兰察布市| 金湖县| 铁岭市| 赤壁市| 灌南县| 曲水县| 廊坊市| 龙海市| 平江县| 甘德县| 五莲县| 鸡东县| 龙口市| 分宜县| 江都市| 遂溪县| 吉安县| 永宁县| 南开区| 晋江市| 衡阳县|