上课闲的没事想到的题,挺水的。。。
只需要计算出每个数被除了多少次,就是优先级的最长下降子序列
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define N 5000005
using namespace std;
int n,a[N],q[N],top,ans[N],t;
int read(){
int a=0;char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9'){a=a*10+ch-'0';ch=getchar();}
return a;
}
int main(){
freopen("divid.in","r",stdin);
freopen("divid.out","w",stdout);
n=read();t=read();
for(int i=1;i<=n-1;i++)a[i]=read();
for(int i=1;i<n;i++){
while(top&&a[i]>q[top])top--;
q[++top]=a[i];
ans[i+1]=top;
}
for(int i=t;i<=n;i+=t)
printf("%d",ans[i]%2);
return 0;
}
本文介绍了一种求解最长下降子序列问题的算法,并通过一个具体的编程实例展示了如何使用C++来实现这一算法。该算法能够计算出一系列数字中被除次数最多的数,适用于解决特定类型的数据结构和算法问题。
1767

被折叠的 条评论
为什么被折叠?



