日志统计
题目大意
小明维护着一个程序员论坛。现在他收集了一份”点赞”日志,日志共有 N N N 行。
其中每一行的格式是:
ts id
表示在 t s ts ts 时刻编号 i d id id 的帖子收到一个”赞”。现在小明想统计有哪些帖子曾经是”热帖”。如果一个帖子曾在任意一个长度为 D D D 的时间段内收到不少于 K K K 个赞,小明就认为这个帖子曾是”热帖”。
具体来说,如果存在某个时刻 T T T 满足该帖在 [ T , T + D ) [T,T+D) [T,T+D) 这段时间内(注意是左闭右开区间)收到不少于 K K K 个赞,该帖就曾是”热帖”。
给定日志,请你帮助小明统计出所有曾是”热帖”的帖子编号。
输入格式
第一行包含三个整数 N , D , K N,D,K N,D,K。
以下 N N N 行每行一条日志,包含两个整数 t s ts ts 和 i d id id。
输出格式
按从小到大的顺序输出热帖 i d id id。
每个 i d id id 占一行。
数据范围: 1 ≤ K ≤ N ≤ 105 , 0 ≤ t s , i d ≤ 105 , 1 ≤ D ≤ 10000 1≤K≤N≤105,0≤ts,id≤105,1≤D≤10000 1≤K≤N≤105,0≤ts,id≤105,1≤D≤10000
输入样例
7 10 2
0 1
0 10
10 10
10 1
9 1
100 3
100 3
输出样例
1
3
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
const int maxn = 1e5 + 7;
int n,k,d;
struct node{
int ts,id; //时间,编号
bool operator < (const node &t) const{
return ts < t.ts;
}
}a[maxn];
int x[maxn];
set<int>st;
int ans[maxn];
int main()
{
cin>>n>>d>>k;
for(int i = 0; i < n; i++) cin>>a[i].ts>>a[i].id;
sort(a,a+n); //按时间从小到大排序
x[a[0].id]++;
for(int i = 0, j = 1; j < n; j++)
{
if(a[j].ts - a[i].ts < d) x[a[j].id]++;
else{
while(a[j].ts - a[i].ts >= d) //不符合条件
{
x[a[i].id]--;
i++;
}
j--;
}
if(x[a[j].id] >= k) st.insert(a[j].id); //热帖
}
for(set<int>::iterator it = st.begin(); it != st.end(); it++)
cout<<*it<<endl;
return 0;
}
献给阿尔吉侬的花束
题目大意
阿尔吉侬是一只聪明又慵懒的小白鼠,它最擅长的就是走各种各样的迷宫。
今天它要挑战一个非常大的迷宫,研究员们为了鼓励阿尔吉侬尽快到达终点,就在终点放了一块阿尔吉侬最喜欢的奶酪。
现在研究员们想知道,如果阿尔吉侬足够聪明,它最少需要多少时间就能吃到奶酪。
迷宫用一个 R × C R×C R×C 的字符矩阵来表示。
字符 S S S 表示阿尔吉侬所在的位置,字符 E E E 表示奶酪所在的位置,字符 KaTeX parse error: Expected 'EOF', got '#' at position 1: #̲ 表示墙壁,字符 . . . 表示可以通行。
阿尔吉侬在 1 个单位时间内可以从当前的位置走到它上下左右四个方向上的任意一个位置,但不能走出地图边界。
输出格式
第一行是一个正整数 T T T,表示一共有 T T T 组数据。
每一组数据的第一行包含了两个用空格分开的正整数 R R R 和 C C C,表示地图是一个 R × C R×C R×C 的矩阵。
接下来的 R R R 行描述了地图的具体内容,每一行包含了 C C C 个字符。字符含义如题目描述中所述。保证有且仅有一个 S S S 和 E E E。
输出格式
对于每一组数据,输出阿尔吉侬吃到奶酪的最少单位时间。
若阿尔吉侬无法吃到奶酪,则输出 “ o o p ! ” “oop!” “oop!”(只输出引号里面的内容,不输出引号)。
每组数据的输出结果占一行。
数据范围: 1 < T ≤ 10 , 2 ≤ R , C ≤ 200 1<T≤10,2≤R,C≤200 1<T≤10,2≤R,C≤200
输入样例
3
3 4
.S..
###.
..E.
3 4
.S..
.E..
....
3 4
.S..
####
..E.
输出样例
5
1
oop!
#include <cstdio>
#include <queue>
using namespace std;
const int maxn = 210;
char s[maxn][maxn];
struct node{
int x,y; //横纵坐标
int step; //步数
};
int dir[4][2] = {
0, 1, -1, 0, 0, -1, 1, 0}; //方向
int l,r,ok;
int sx, sy, ex, ey; //起点,终点
bool inbound(int x, int l, int r) //判断方向是否合法
{
if(x < l || x >= r) return true;
return false;
}
void bfs(node tt)
{
queue<node> q;
q.push(tt);
while(!q.empty())
{
node now = q.front(); q.pop();
if(now.x == ex && now.y == ey) //到达终点
{
printf("%d\n",now.step); ok = 1;
return ;
}
for(int i = 0; i < 4; i++)
{
node ne;
ne.x = now.x + dir[i][0];
ne.y = now.y + dir[i][1];
ne.step = now.step + 1;
if(!inbound(ne.x, 0, l) && !inbound(ne.y, 0, r) && s[ne.x][ne.y] != '#')
{
s[ne.x][ne.y] = '#';
q.push(ne);
}
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf(" %d%d",&l,&r);
for