- 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.
Input 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.
Output For each test case, display a single line containing the case number and the minimum possible number of buildings in the photo.
Sample Input
3 1 2 3 3 1 2 1
Sample Output
Case 1: 3 Case 2: 2 Hint The possible configurations of the samples are illustrated below:< http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcHJlPgoKIAo8cD48YnI+CiA8L3A+CjxwPtXitcDM4svjysexyL3PxNHA7b3itcTByzwvcD4KPHA+zOLS4jo8YnI+CtK71cXP4Masyc+1xLrctuC9qNb+z+C7pdXa16HByyy4+b7duN+1zbK7zay+zdTaz+DGrMnPsNHSu9f5uN/CpbXEv8m8+7K/t9bX986q0ru49r7Y0M4sPGJyPgqyotPDyv3X1sPoyvbG5LjftsgsyPTSu9XFz+DGrMnPtcTBvbj2vajW/si61tC85NPQv9W12Cy437bI1PLOqjA7x/PX7snZ09C24MnZuPa9qNb+Ozxicj4Ky7zCtzo8YnI+CjEgMiAx1+7J2c6qMtf5LNLyzqoysNExtbLXocHLLLb4MyAxIDPU8s6qM9f5LDG1srK716EzOzxicj4KyOc6MSAyIDMgMSAyIDMgMCAxPGJyPgrK5MjrtcQwsrvKx72o1v4s1PLK5MjrtcTX3Lj2yv289cilMLXEuPbK/b7NysfX7rbgv8nE3NPQtcS9qNb+yv0syejOqnM7PGJyPgrU2bTTtdrSu7j2v6rKvLTTx7DN+brzy9EsyPS3os/WscjL/LjftcTU8rzM0PjL0SzI9Leiz9axyMv8tc21xNTyy7XD98v8ysfSu7j2tsDBorXEvajW/iw8YnI+CtXiyrG/ydLUt7W72MvRxuTL/LXEO8j00+vL/M/gtcgsy7XD99XiyrHL/MPHu7nDu9PQs/bP1rHIy/zDx7XNtcS9qNb+LNTyytPG5M6qzazSu7j2vajW/iw8YnI+CtTyc7z1MTs8L3A+CjxwPiA8L3A+CjxwPiA8L3A+CjxwcmUgY2xhc3M9"brush:java;">#include ![]()
#include #include 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 =0; j--) { if(a[i]>a[j]) break; else if(a[i]==a[j]) { ans++; break; } } } } printf("Case %d: %d\n",cas++,n-ans); } return 0; }