思路大概是每来一个人,就给他一个时限(即到的时间加上二十四小时)在这个时限内就说明他还在当地
然后每来一艘船进行一次循环,如果船到时间在这个人的时限内,就人数加一,最后输出人数
其实我想到了其他解法,但我实在是不舍得这个解法(或许是他很短?小小的真可爱)看看有没有大佬愿意优化一下
附上代码
#include<iostream>
#include<queue>
using namespace std;
const int xmax = 100005;
int t, n, k, x;//t秒到,n艘船,k个人,x为国籍
int word[xmax] = { 0 };
int main() {
cin >> n;
for (int j = 0; j < n; j++) {
int ans=0;
cin >> t >> k;
for (int i = 0; i < k; i++) {
cin >> x;
word[x] = t + 86399;
}
for (int i = 1; i <= xmax; i++) {
if (word[i] >= t) ans += 1;
}
cout << ans << endl;
}
return 0;
}