题目:
分析:
通过
v
e
c
t
o
r
vector
vector将各种色调的客栈分开,然后暴力求解
因为我们一开始是从前往后,所以我们可以从后往前求解,一旦当前这个方案是合法的,那么前面的方案一定包含了这个方案,从而快速求解
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#define LL long long
using namespace std;
inline LL read(){
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
int min(int x,int y) {return x<y? x:y;}
int minn[55],w[200005];
vector<int> v[55];
int main()
{
int tf;
int n=read(),m=read(),p=read(),ans=0;
memset(minn,0x7f,sizeof(minn));
for(int i=1;i<=n;i++)
{
int u=read();w[i]=read();
v[u].push_back(i);
if(v[u].size()==1) continue;
if(w[i]<=p) {ans+=v[u].size()-1;continue;}
int king=0;
for(int j=(int)v[u].size()-2;j>=0;j--)
{
tf=0;
for(int k=v[u][j];k<=i;k++)
if(w[k]<=p) {tf=1;break;}
if(tf) {ans+=v[u].size()-1-king;break;}
else king++;
}
}
cout<<ans;
return 0;
}