Input
8 4 4
7 2
3 3
4 5
5 1
2 2
1 4
8 4
9 4
6 1 4 9
Output
2
2
3
2

题意:有n条鱼,m个渔夫,且这m个渔夫都在横坐标轴上,每个渔夫都有一个长度为L的鱼竿,当鱼和渔夫距离小于或等于L时,鱼能被钓到。并且渔夫(x,0)与鱼(a,b)的距离满足如下公式   |a − x| + b.      式子中x为渔夫的横坐标,(a,b)为鱼的坐标。

思路: 我们可以先把渔夫的位置排个序,然后遍历所有的鱼,每一条鱼能够被可以被抓都在x轴有一个范围,通过二分,在渔夫中找到最左的和最右的,然后差分一下,最后求个前缀和就可以得出答案。

用到的知识:

简单来讲就是: a是数组,n是数组里面的个数,x是需要比较的数,其中a数组是从1开始计数,用之前需要对a数组排序。
lower_bound(a+1, a+n+1,x)-a是返回一个非递减序列[first, last)中的第一个大于等于值x的位置。

upper_bound(a+1, a+n+1, x)-a算法返回一个非递减序列[first, last)中第一个大于x的位置。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=2e5+10;
#define inf 0x3f3f3f
struct Fish
{int x;int y;
}fish[M];
struct Fishman
{int pos;//渔夫的位置int before;//排序前位置的编号int after;//排序后位置的编号bool operator <(const Fishman &bb) const{return pos<bb.pos;}
}fishman[M];
int sum[M],ans[M];
int main()
{ll n,m,l,i,j;scanf("%d%d%d",&n,&m,&l);for(i=1;i<=n;i++)scanf("%d%d",&fish[i].x,&fish[i].y);for(i=1;i<=m;i++){scanf("%d",&fishman[i].pos);fishman[i].before=i;}sort(fishman,fishman+m+1);for(i=1;i<=m;i++)fishman[i].after=i;for(i=1;i<=n;i++){if(fish[i].y-l>0)continue;Fishman temp;//x-(l-y) ~ x+(l-y)temp.pos=fish[i].x-l+fish[i].y;int xx=lower_bound(fishman+1,fishman+m+1,temp)-fishman;temp.pos=fish[i].x+l-fish[i].y;int yy=upper_bound(fishman,fishman+m+1,temp)-fishman;sum[xx]++;sum[yy]--;}for(int i=1;i<=m;i++){sum[i]+=sum[i-1];ans[fishman[i].before]=sum[fishman[i].after];}for(i=1;i<=m;i++)printf("%d\n",ans[i]);return 0;
}

Fishermen(2018 ICPC SouthEastern European)相关推荐

  1. 2020-2021 ICPC Southeastern European Regional Programming Contest (SEERC 2020)

    2020-2021 ICPC Southeastern European Regional Programming Contest (SEERC 2020) B. Reverse Game 题目描述: ...

  2. 2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018)

    2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018) 题号 题目 知识点 难度 A Access ...

  3. 2018 ICPC Asia Jakarta Regional Contest

    2018 ICPC Asia Jakarta Regional Contest 题号 题目 知识点 难度 A Edit Distance B Rotating Gear C Smart Thief D ...

  4. 2021 ICPC Southeastern Europe Regional Contest Werewolves(树上背包)

    2021 ICPC Southeastern Europe Regional Contest Werewolves(树上背包) 链接 题意:给出一个n个节点的树(n≤3000n\le3000n≤300 ...

  5. 2021 ICPC Southeastern Europe Regional Contest(更新至六题)

    2021 ICPC Southeastern Europe Regional Contest A题签到 A. King of String Comparison 题意:给两个字符串,找出有多少对(l, ...

  6. 2018 ICPC 南京 M. Mediocre String Problem(ExKMP + Manacher / ExKMP+回文树)

    2018 ICPC 南京 全文见:https://blog.csdn.net/qq_43461168/article/details/112796538 M. Mediocre String Prob ...

  7. Gym 101964 2018-2019 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2018)

    传送门 A.Numbers B.Broken Watch 先考虑最简单的情况,就是a,b,c都相等的情况,这个时候答案显然只会跟n有关系,在n个线段里面选3个的情况就是C(n,3),其中有一部分不合法 ...

  8. 2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018)记录

    A. Access Points 待更 B. Brexit Negotiations 题意:给一个 DAG,最小化[每个点点权与其在拓扑序内的编号之和的最大值],输出这个最小值. 解法:反向建图,然后 ...

  9. 2018 ICPC 沈阳站

    细胞色素训练3 排名:100/193 2018年ICPC沈阳站,学长在这里拿金了.听学长说开始时候很快的出了两题,排名第四,是可以进final的,然后一直没过题,直到最后封榜时候连过两题,金牌最后一名 ...

  10. ZOJ 4062 Plants vs. Zombies 2018 ICPC 青岛站 E Plants vs. Zombies

    ZOJ 4062 二分 哎,二分,二分,二分,我咋就没想到啊,在一篇博客上看到一句话: 一般此类最小值最大问题都是二分,此题显然也是可以二分植物的高度的. 博客链接:https://www.cnblo ...

最新文章

  1. Android --- 订单编号怎样不重复?一秒钟如果有n个人同时下单怎么解决?凌晨12点限量抢购1000件商品,直到抢完为止订单编号怎么处理?
  2. python下几种打开文件的方式
  3. ASP.NET Core MVC中的 [Required]与[BindRequired]
  4. webpack联邦模块之webpack运行时
  5. 软件测试除了边界值还有什么,在软件测试中,假定 X 为整数,10≤X≤100,用边界值分析法,那么 X 在测试 中应该取( )边界值...
  6. 物理层上/下行每个功能块需要的信息
  7. HYSBZ/BZOJ 1007 [HNOI2008] 水平可见直线 - 计算几何
  8. 计算机操作系统第三章测试题及答案
  9. 故障:Outlook 收发邮件时的 0x800CCC1A 错误
  10. 狂神说Vue笔记整理
  11. Java自动生成编号
  12. 关于子函数的调用和终止
  13. latex设置页面大小边距行距等
  14. Mybatis遇到的报错集合
  15. 【视频学习】12堂快速阅读课,10倍提升阅读效率
  16. EAUML日拱一卒-微信小程序实战:位置闹铃 (6)-播放音频
  17. 2019年寒假 纪中培训总结
  18. 为什么你只需要CD音质:16bits, 44.1kHz的意义
  19. 「自控元件及线路」6 无刷直流电动机
  20. 解析ArcGis的字段计算器(四)——日期字段计算

热门文章

  1. 清空计算机网络缓存,如何清除DNS缓存 使用命令清理DNS缓存方法
  2. WIN10专业版无法隐藏任务栏图标
  3. LSF集群作业管理系统
  4. Leaflet制作专题图
  5. aws----文件存储efs的全面了解
  6. 【Hive】Establishing SSL connection without server‘s identity verification is not recommended. Accord
  7. 阿里云ECS上使用docker搭建filebeat+kafka集群+zookeep集群+logstash+elasticsearch集群+kibana实现跨主机日志收集系统【四】
  8. 计算机的单位换算字节,关于计算机的存储字节单位换算和使用
  9. ConneR and the A.R.C. Markland-N
  10. java pack unpack_pack/unpack函数与二进制