得分:100+40+0;
T1 购买板凳
题意: 给出n个时间段 时间段内要容纳 x个人 求所需容量
区间头和尾标记 扫一遍找最大值
样例:
【输入样例1】
2
6 08:00 09:00
5 08:59 09:59
【输出样例1】
11
【输入样例2】
2
6 08:00 09:00
5 09:00 10:00
【输出样例2】
6
2
6 08:00 09:00
5 08:59 09:59
【输出样例1】
11
【输入样例2】
2
6 08:00 09:00
5 09:00 10:00
【输出样例2】
6
#include<bits/stdc++.h>
using namespace std;
int n,x,a,b,s,ans;
int f[1440];
int read(){
int i=0,f=1;char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') f=-1;
for(;ch<='9'&&ch>='0';ch=getchar()) i=(i<<3)+(i<<1)+ch-'0';
return i*f;
}
int main(){
// freopen("chair.in","r",stdin);
// freopen("chair.out","w",stdout);
n=read();
for(int i=1;i<=n;++i){
x=read();a=read()*60;a+=read();b=read()*60;b+=read();
f[a]+=x;f[b]-=x;
}
for(int i=0;i<1440;++i){
s+=f[i];
ans=max(ans,s);
}
cout<<ans<<endl;
return 0;
}
T2 新排序
题意:T组数据 每组数据给出一个数N和 N个数序列
对于a[i]>a[i+1] 称a[i]、a[i+1]为不和谐数字
每次删除所有不和谐数字 直到没有不和谐数字
样例:
【输入样例】
4
5
1 2 3 4 5
5
5 4 3 2 1
5
1 2 3 2 1
5
2 4 1 3 5
【输出样例】
5
1 2 3 4 5
0
2
1 2
3
2 3 5
5
1 2 3 4 5
5
5 4 3 2 1
5
1 2 3 2 1
5
2 4 1 3 5
【输出样例】
5
1 2 3 4 5
0
2
1 2
3
2 3 5
考试的时候想用栈来维护的 后来打暴力对拍发现有问题 最后就交个暴力吧
#include<bits/stdc++.h>
using namespace std;
int T,n,a[100005],f[100005];
int stu[2][100005],top[2],now,pre;
int read(){
int i=0,f=1;char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') f=-1;
for(;ch<='9'&&ch>='0';ch=getchar()) i=(i<<3)+(i<<1)+ch-'0';
return i*f;
}
int main(){
// freopen("sort.in","r",stdin);
// freopen("bl.out","w",stdout);
T=read();
while(T--){
memset(f,true,sizeof(f));
memset(stu,0,sizeof(stu));
n=read();top[0]=n;now=0;pre=1;
for(int i=1;i<=n;++i) stu[now][i]=read();
for(int t=1;t<=200;++t){
top[pre]=0;
for(int i=1;i<=top[now];++i){
if(i>1&&stu[now][i-1]>stu[now][i]) continue;
if(i<top[now]&&stu[now][i]>stu[now][i+1]) continue;
stu[pre][++top[pre]]=stu[now][i];
}
pre=now;now^=1;
}
cout<<top[now]<<endl;
for(int i=1;i<=top[now];++i)
cout<<stu[now][i]<<" ";
cout<<endl;
}
}
标算:先把下降序列删除,对于剩下的上升序列 比较序列与序列相交的地方 按要求删除
#include<bits/stdc++.h>
using namespace std;
int T,n,f;
int a[100005],l[100005],r[100005];
bool b[100005];
int read(){
int i=0,f=1;char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') f=-1;
for(;ch<='9'&&ch>='0';ch=getchar()) i=(i<<3)+(i<<1)+ch-'0';
return i*f;
}
void clear(){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
}
int main(){
// freopen("sort.in","r",stdin);
// freopen("sort.out","w",stdout);
T=read();
while(T--){
clear();
n=read();
queue<int>q,q2,q3;
for(int i=1;i<=n;++i) a[i]=read(),l[i]=i-1,r[i]=i+1;
a[n+1]=2147483647;
for(int i=1;i<=n;++i) if((a[l[i]]>a[i]||a[i]>a[r[i]])) q.push(i);
while(!q.empty()){
while(!q.empty()){
int u=q.front();
q.pop(), q3.push(u);
if(a[l[u]]<=a[u]&&l[u]>=0) q2.push(l[u]);
if(a[u]<=a[r[u]]&&r[u]<=n) q2.push(r[u]);
}
while(!q3.empty()){
int u=q3.front();
b[u]=1, q3.pop(), l[r[u]]=l[u], r[l[u]]=r[u];
}
while(!q2.empty()){
int u=q2.front();
q2.pop();
if(!b[u]&&(a[l[u]]>a[u]||a[u]>a[r[u]])) q.push(u);
}
}
int ans=0;
for(int i=1;i<=n;++i) if(!b[i]) ++ans;
cout<<ans<<endl;
for(int i=1;i<=n;++i) if(!b[i]) cout<<a[i]<<" ";
cout<<endl;
}
}
T3 豆豆游戏
类似祖玛 一道DP题