#include<bits/stdc++.h> using namespace std; int n,p[1000001],sum,x,y,ct; struct sa{ int c,t; }; queue<sa> q; int main(){ scan

沈泽宇  •  1年前


include<bits/stdc++.h>

using namespace std; int n,p[1000001],sum,x,y,ct; struct sa{

int c,t;

}; queue q; int main(){

scanf("%d",&n);
for(int i=1;i<=n;i++){
	scanf("%d%d",&x,&y);
	sa tmp;
	tmp.t=x;
	for(int j=1;j<=y;j++){
		scanf("%d",&ct);
		tmp.c=ct;
		q.push(tmp);
		if(!p[ct]) sum++;
		p[ct]++;
	}
	while(1){
		sa front=q.front();
		if(tmp.t-front.t>=86400){
			int tc=front.c;
			p[tc]--;
			if(!p[tc]) sum--;
			q.pop();
		}
		else break;
	}
	printf("%d\n",sum);
}
return 0;

}


评论:

/#include<bits/stdc++.h> using namespace std; const int N=20,INF=1e9; int n,m,c,r; int a[N][N],dp[N][N],cw[N]; int rw[N][N],q[N],ans=1e9; int ct(int x){

int s=0;
for(int i=0;i<n;i++)
	s+= x>>i &1;
return s;

} int main(){

cin>>n>>m>>r>>c;
for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
		cin>>a[i][j];
for(int i=0;i< 1<<n ;i++){
	if(ct(i)==r){
		for(int j=0,k=0;j<n;j++)
			if(i>>j &1)
				q[k++]=j;
		for(int j=0;j<m;j++){
			cw[j]=0;
			for(int k=1;k<r;k++)
				cw[j]+=abs(a[q[k]][j]-a[q[k-1]][j]);
		}
		for(int j=0;j<m;j++){
			for(int k=j+1;k<m;k++){
				rw[j][k]=0;
				for(int d=0;d<r;d++)
					rw[j][k]+=abs(a[q[d]][j]-a[q[d]][k]);
			}
		}
		for(int j=0;j<m;j++){
			dp[j][1]=cw[j];
			for(int k=2;k<=c;k++){
				dp[j][k]=INF;
				for(int d=0;d<j;d++)
					dp[j][k]=min(dp[j][k],dp[d][k-1]+cw[j]+rw[d][j]);
			}
			ans=min(ans,dp[j][c]);
		}
	}
}
cout<<ans;
return 0;

}


陈浩轩  •  1年前