标签:des style blog http color io os ar java
3 1 2 3 3 1 2 1
Case 1: 3 Case 2: 2
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 100010; 18 int d[maxn],n,m; 19 int main(){ 20 int cs = 1; 21 while(~scanf("%d",&n)){ 22 for(int i = 0; i < n; ++i){ 23 scanf("%d",d+i); 24 } 25 m = n; 26 if(d[0] == 0) --m; 27 for(int i = 1; i < n; ++i){ 28 if(d[i] == 0) m--; 29 else{ 30 for(int j = i-1; j >= 0; --j){ 31 if(d[j] < d[i]) break; 32 if(d[j] == d[i]){ 33 --m; 34 break; 35 } 36 } 37 } 38 } 39 printf("Case %d: %d\n",cs++,m); 40 } 41 return 0; 42 }
单调栈
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 stack<int>stk; 18 int main(){ 19 int cs = 1,tmp,n; 20 while(~scanf("%d",&n)){ 21 while(!stk.empty()) stk.pop(); 22 int ans = 0; 23 for(int i = 0; i < n; ++i){ 24 scanf("%d",&tmp); 25 while(!stk.empty() && stk.top() > tmp){ 26 ans++; 27 stk.pop(); 28 } 29 if(tmp && (stk.empty() || tmp > stk.top())) stk.push(tmp); 30 } 31 printf("Case %d: %d\n",cs++,ans + stk.size()); 32 } 33 return 0; 34 }
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/crackpotisback/p/4032771.html