专栏文章
题解:P12987 [GCJ 2022 #1B] Pancake Deque
P12987题解参与者 2已保存评论 3
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mip0mto2
- 此快照首次捕获于
- 2025/12/03 04:13 3 个月前
- 此快照最后确认于
- 2025/12/03 04:13 3 个月前
P12987 [GCJ 2022 #1B] Pancake Deque
思路
先使队列两端较小值出列,可使美味值最大值增长更缓慢。
这样后续煎饼更容易满足支付条件(只需 较小值而非较大值),增加后续付费机会。
注意
当一个煎饼的美味值不低于之前所有煎饼的美味值时,该顾客才为其煎饼付费。
完整代码
CPP#include<bits/stdc++.h>
using namespace std;
int main(){
int T;
cin>>T;
for(int i=1;i<=T;i++){
int n;
int last=0; //之前所有顾客获得的煎饼的美味值最大值
int sum=0; //付费顾客数量
list<int> d; //煎饼!
cin>>n;
while(n--){ //输入
int x;
cin>>x;
d.push_back(x);
}
while(!d.empty()){
if(d.front()>d.back()){ //判断队首和队尾煎饼的美味值
if(d.back()>=last)last=d.back(),sum++; //判断是否不低于之前所有顾客获得的煎饼的美味值
d.pop_back(); //出队
}else{ //同上
if(d.front()>=last)last=d.front(),sum++;
d.pop_front();
}
}
printf("Case #%d: %d\n",i,sum);
}
}
相关推荐
评论
共 3 条评论,欢迎与作者交流。
正在加载评论...