题解:P2058 [NOIP2016 普及组] 海港

点击这里看题目

刚开始写的时候把题目看错了
写了个40分代码如下:

#include<iostream>
#include<iterator>
#include<set>
using namespace std;

set<int>now; 
int a[300000];
int t[86401]; 
int main(){
	int n;
	int t,k;
	cin>>n;
	int i=1;
	while(n--){
		
	    cin>>t>>k;
	    for(int i=1;i<=k;i++){
		cin>>a[i];
		now.insert(a[i]);
		}
		cout<<now.size()<<endl;
	} 
	return 0;
} 

后来发现本土时间t是有用的考察的东西就是队列,要不断的淘汰24小时之前来的船上的人
AC代码:

#include<iostream>
#include<queue>
using namespace std;

struct node{
	int s,t;
};
int n,t,m;
int x;
int temp_nation[100005]; 
queue<node>ship;
node h;
int ans=0;

int main(){
	cin>>n; 
	for(register int i=1;i<=n;i++){
		cin>>t>>m; 
		while(!ship.empty()){
			h=ship.front();
			if(h.t+86400<=t){
			   temp_nation[h.s]--;
			   if(temp_nation[h.s]==0)
			   ans--;
			   ship.pop();
			   continue;
			}
			break;
	    }
	    for(register int j=1;j<=m;j++){
	    	cin>>x;
	    	h.s=x;
	    	h.t=t;
	    	ship.push(h);
	    	temp_nation[x]++;
	    	if(temp_nation[x]==1)
	    	ans++;
		}
			cout<<ans<<endl;
	}
	return 0;
}

版权声明:本文为weixin_45336453原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。