2017-2018 ACM-ICPC Northern Eurasia(A.Archery Tournament)
题目链接:https://vjudge.net/problem/Gym-101630A
题意: n个事件,t=1 代表增加一个圆心为(x,y),半径为 abs(y)的靶子,t=2,代表射击的坐标为(x,y)并且询问是否在已出现的靶子上,如果在则输出第几个事件的编号,否则输出-1。
该题有个坑点:(一开始没看到)一个靶子只能被射击一次。
思路:可以用set存每个靶子的位置,但是需要对靶子按照前后空隙大小进行排序,这样之后我们就可以通过射击点的横坐标对set二分查找出最靠近其的靶子,然后就可以往后遍历是否存在一个靶子使得子弹在上面,但是光这样做在P5 就T了,仔细想了想发现,我们之前排序的作用,一旦我们的 x<x1-abs(y) 那么后面的靶子也不用再遍历了,直接退出循环,这样就会减少很多不必要的操作。
然后还有简单的题解是通过线段树维护暴搜就好了:https://blog.csdn.net/lzc504603913/article/details/83958171
代码:
- int n;
- struct node{
- ll x,y,id;
- bool operator<(const node a) const {
- return x+abs(y)<a.x-abs(a.y); //排序方法
- }
- };
- bool dis(ll x1,ll y1,ll a,ll b)
- {
- return (x1-a)*(x1-a)+(y1-b)*(y1-b)<y1*y1;
- }
- set<node>s;
- void run()
- {
- scanf("%d",&n);
- ll t,a,b;
- for(int i=1;i<=n;i++)
- {
- scanf("%lld%lld%lld",&t,&a,&b);
- if(t==1)
- {
- node Node;
- Node.x=a;
- Node.y=b;
- Node.id=i;
- s.insert(Node);
- }
- else{
- node tmp;
- bool flag=0;
- tmp.x=a;
- tmp.y=0;
- set<node>::iterator it=s.lower_bound(tmp);
- while(it!=s.end())
- {
- ll x1=it->x,y1=it->y;
- if(dis(x1,y1,a,b))
- {
- flag=true;
- printf("%lld\n",it->id);
- s.erase(it);
- break;
- }
- if(it->x-a>abs(it->y)) break;//关键2;
- it++;
- }
- if(!flag) puts("-1");
- }
- }
- }
- signed main()
- {
- // int t=rd();
- // while(t--)
- run();
- return 0;
- }
线段树的方法:
- #include<iostream>
- #include<deque>
- #include<memory.h>
- #include<stdio.h>
- #include<map>
- #include<string>
- #include<algorithm>
- #include<vector>
- #include<math.h>
- #include<stack>
- #include<queue>
- #include<bitset>
- #include<set>
- #define INF (0x3f3f3f3f)
- using namespace std;
- typedef long long int ll;
- const int MAXN=200010;
- ll X[MAXN];
- ll Y[MAXN];
- int tot;
- vector<int> V[MAXN*30];
- int ls[MAXN*30];
- int rs[MAXN*30];
- int ans;
- bool check(ll x1,ll y1,ll x2,ll y2){
- if((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)<y1*y1)
- return 1;
- return 0;
- }
- void update(int L,int R,int C,int l,int r,int &rt){
- if(!rt)
- rt=++tot;
- if(L<=l&&r<=R)
- {
- V[rt].push_back(C);
- return;
- }
- int m=(l+r)>>1;
- if(L<=m)
- update(L,R,C,l,m,ls[rt]);
- if(R>m)
- update(L,R,C,m+1,r,rs[rt]);
- }
- void update(int L,int R,int l,int r,int rt){
- if(L<=l&&r<=R){
- vector<int> tmp;
- for(auto &t:V[rt]){
- if(t!=ans){
- tmp.push_back(t);
- }
- }
- V[rt]=tmp;
- return;
- }
- int m=(l+r)>>1;
- if(L<=m)
- update(L,R,l,m,ls[rt]);
- if(R>m)
- update(L,R,m+1,r,rs[rt]);
- }
- void query(int L,int R,int l,int r,int rt){
- if(!rt)
- return;
- for(auto &t:V[rt]){
- if(check(X[t],Y[t],L,R)){
- ans=t;
- return;
- }
- }
- if(l==r)
- return;
- int m=(l+r)>>1;
- if(L<=m)
- query(L,R,l,m,ls[rt]);
- else
- query(L,R,m+1,r,rs[rt]);
- }
- int main(){
- int N;
- scanf("%d",&N);
- int rt=0;
- for(int i=1;i<=N;i++){
- int op,x,y;
- scanf("%d%d%d",&op,&x,&y);
- if(op==1){
- X[i]=x;
- Y[i]=y;
- update(x-y,x+y,i,-INF,INF,rt);
- }
- else{
- ans=-1;
- query(x,y,-INF,INF,rt);
- printf("%d\n",ans);
- if(ans!=-1)
- update(X[ans]-Y[ans],X[ans]+Y[ans],-INF,INF,rt);
- }
- }
- return 0;
- }
2017-2018 ACM-ICPC Northern Eurasia(A.Archery Tournament)的更多相关文章
- 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)
链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...
- 牛客网暑期ACM多校训练营(第五场):F - take
链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...
- 牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献)
牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献) 链接:https://ac.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy ha ...
- 2018牛客网暑期ACM多校训练营(第三场) A - PACM Team - [四维01背包][四约束01背包]
题目链接:https://www.nowcoder.com/acm/contest/141/A 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- Trace 2018徐州icpc网络赛 (二分)(树状数组)
Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx ...
- 2018牛客网暑期ACM多校训练营(第四场) A - Ternary String - [欧拉降幂公式][扩展欧拉定理]
题目链接:https://www.nowcoder.com/acm/contest/142/A 题目描述 A ternary string is a sequence of digits, where ...
- 2018牛客网暑期ACM多校训练营(第十场)A Rikka with Lowbit (树状数组)
链接:https://ac.nowcoder.com/acm/contest/148/A 来源:牛客网 Rikka with Lowbit 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C ...
- 2018 ACM ICPC 南京赛区 酱油记
Day 1: 早上6点起床打车去车站,似乎好久没有这么早起床过了,困到不行,在火车上睡啊睡就睡到了南京.南航离南京南站很近,地铁一站就到了,在学校里看到了体验坐直升机的活动,感觉很强.报道完之后去吃了 ...
随机推荐
- online QRcode generator , QRcode=== (Quick Response Code) , 二维条码,二维码,彩色二维码,图片二维码,
online QRcode generator , QRcode=== (Quick Response Code) , 二维条码,二维码,彩色二维码,图片二维码, 1 http://cli.i ...
- TypeScript 1.7 & TypeScript 1.8
TypeScript 1.7 & TypeScript 1.8 1 1 https://zh.wikipedia.org/wiki/TypeScript TypeScript是一种由微软开发的 ...
- js 快速排序 All In One
js 快速排序 All In One 快速排序 / Quick Sort "use strict"; /** * * @author xgqfrms * @license MIT ...
- Full Stack Web Development
Full Stack Web Development Web Stacks MEAN (Mongo, Express, Angular and Node) LAMP (Linux, Apache, M ...
- GitHub user language statistics
GitHub user language statistics 2020 https://madnight.github.io/githut/#/pull_requests/2020/2 2011 ~ ...
- 官网GitLab CI/CD英文文档翻译
在查阅GitLab官网的CI/CD功能说明时,全是英文看起来不方便,通过翻译软件自动翻译后"内容失真",看起来很变扭.查阅了百度上的资料发现很多翻译很老旧,有些甚至是挂羊头卖狗肉. ...
- react性能提升
1.把.bind(this)提升到constructor里面 2.在生命周期函数里面shouldComponentupdate里面做父组件改变重新渲染以致于子组件重新渲染的禁止 3.在setstate ...
- net里面using的使用
起初using就明白一个作用 那就是引用命名空间.当面试官听到我回答这个问题的时候,马上就还问我,还有什么作用?我就只能摇头了,今天在网上看了下using的作用. 1.using指令.using + ...
- Java之HTTP网络编程(一):TCP/SSL网页下载
目录 一.简介:HTTP程序设计 1.HTTP系统设计 2.HTTP客户端工作过程 3.HTTP服务端工作过程 二.基于TCP Socket的HTTP网页下载 三.基于SSL Socket的HTTPS ...
- 一次 MySQL 线上死锁分析实战
关键词:MySQL Index Merge 前言 MySQL 的锁机制相信大家在学习 MySQL 的时候都有简单的了解过,那既然有锁就必定绕不开死锁这个问题.其实 MySQL 在大部分场景下是不会存在 ...