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点起床打车去车站,似乎好久没有这么早起床过了,困到不行,在火车上睡啊睡就睡到了南京.南航离南京南站很近,地铁一站就到了,在学校里看到了体验坐直升机的活动,感觉很强.报道完之后去吃了 ...
随机推荐
- 内网域渗透之MS14-068复现(CVE-2014-6324)
在做域渗透测试时,当我们拿到了一个普通域成员的账号后,想继续对该域进行渗透,拿到域控服务器权限.如果域控服务器存在MS14_068漏洞,并且未打补丁,那么我们就可以利用MS14_068快速获得域控服务 ...
- PostCSS All In One
PostCSS All In One https://postcss.org/ https://www.webpackjs.com/loaders/postcss-loader/ https://gi ...
- fibonacci all in one
fibonacci all in one fibonacci sequence https://www.mathsisfun.com/numbers/fibonacci-sequence.html f ...
- Microsoft Lifecycle Policy
Microsoft Lifecycle Policy The Microsoft Lifecycle Policy gives you consistent and predictable guide ...
- VS Code Extension
VS Code Extension https://code.visualstudio.com/api/get-started/your-first-extension xgqfrms 2012-20 ...
- Azure 信用卡扣款 1 美元 & Azure 中国客服
Azure 信用卡扣款 1 美元 & azure 中国客服 Azure 免费帐户常见问题 https://azure.microsoft.com/zh-cn/free/free-account ...
- Flutter:发布包
[package] 生成包含模块化Dart代码的可共享Flutter项目 [plugin] 生成一个可共享的Flutter项目, 在Dart代码中包含带有API的API, 针对Android的平台特定 ...
- 「NGK每日快讯」12.17日NGK第44期官方快讯!
- (转)linux下的系统调用函数到内核函数的追踪
转载网址:http://blog.csdn.net/maochengtao/article/details/23598433 使用的 glibc : glibc-2.17使用的 linux kerne ...
- 敏捷史话(七):从程序员、作家到摇滚乐手——Andy Hunt的多面人生
与其说 Andy Hunt 是敏捷宣言的创始人,不如说他是一名专业作家来得更为合适.他的<实用程序员><程序员修炼之道:从小工到专家><编程 Ruby:实用程序员指南&g ...