码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 27 D. Driving Test

时间:2019-06-29 22:05:07      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:max   code   str   force   return   for   fine   nbsp   print   

 

单调栈

 

题意看了半天。。。

 

 1     #include <cstdio>
 2     #include <cstdlib>
 3     #include <cmath>
 4     #include <cstring>
 5     #include <string>
 6     #include <algorithm>
 7     #include <iostream>
 8     using namespace std;
 9     #define ll long long
10      
11     const int maxn=2e5+10;
12     const int inf=1e9;
13      
14     int sum1,tot1;
15     int f[maxn],g;
16      
17     int main()
18     {
19         int n,a,b,i,j,v;
20         scanf("%d",&n);
21         for (i=1;i<=n;i++)
22         {
23             scanf("%d",&a);
24             if (a==1 || a==3)
25                 scanf("%d",&b);
26      
27             if (a==4)
28                 tot1=0;
29             else if (a==6)
30                 tot1++;
31             else if (a==2)
32                 sum1+=tot1,tot1=0;
33      
34             if (a==5)
35                 g=0;
36             else if (a==1)
37             {
38                 v=b;
39                 while (g>0 && f[g]<v)
40                     g--,sum1++;
41             }
42             else if (a==3)
43             {
44                 if (b<v)
45                     sum1++;
46                 else
47                     f[++g]=b;
48             }
49         }
50         printf("%d",sum1);
51         return 0;
52     }

 

Educational Codeforces Round 27 D. Driving Test

标签:max   code   str   force   return   for   fine   nbsp   print   

原文地址:https://www.cnblogs.com/cmyg/p/11108010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!