社区讨论
尺取的模板题WA了一片
题目总版参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi85xja8
- 此快照首次捕获于
- 2025/11/21 09:09 4 个月前
- 此快照最后确认于
- 2025/11/21 09:09 4 个月前
求dalao帮帮忙趴qwq
样例过了,不过还是WA了
应该是代码正确性的问题emm
样例过了,不过还是WA了
应该是代码正确性的问题emm
题面:
有t组测试数据,每组给出N个正整数(10 <N <100 000)的序列,每个正整数小于或等于10000,并且给出正整数S(S <100 000 000)。编写程序以找到序列的连续元素的子序列的最小长度,其总和大于或等于S.
样例输入:
CPP样例输入:
2
10 15
5 1 3 5 10 7 4 9 2 8
5 11
1 2 3 4 5
样例输出:
CPP2
3
代码:
CPP#include<cstdio>
#include<queue>
#define maxn 100010
using namespace std;
inline int read(){
int x=0,t=1; char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if(ch=='-') t=-1,ch=getchar();
while(ch<='9'&&ch>='0') x=x*10+ch-48,ch=getchar();
return x*t;
}
queue<int> q;
priority_queue<int,vector<int>,greater<int> >qq;
int n,s;
int a,sum;
int ans;
int main(){
int t;
t=read();
while(t--){
while(!q.empty()) q.pop();
while(!qq.empty()) qq.pop();
sum=0;
n=read(); s=read();
for(register int i=1;i<=n;++i){
a=read(); sum+=a;
q.push(a);
while(sum>=s){
int q_size=q.size();
qq.push(q_size);
int q_front=q.front();
q.pop();
sum-=q_front;
}
}
if(!qq.empty()) ans=qq.top();
printf("%d\n",ans);
}
return 0;
}
来源:poj3061
回复
共 1 条回复,欢迎继续交流。
正在加载回复...