Gym
来源:互联网 发布:淘宝要怎么重新注册 编辑:程序博客网 时间:2024/05/21 14:45
题意
这道题的题意说的是按顺序给出原盘和射击点,原盘坐标是x,y是确定放置在水平轴上的
分析
因为是放在水平轴上,那么在对于一个x轴,相同的x不可能有多个y,并且在一个x轴区间内不会有太多的原盘,那么可以对x轴进行排序查找。
import java.util.Iterator;import java.util.Scanner;import java.util.TreeSet;public class Main { static class Target implements Comparable<Target>{ long x,y; int i; public Target(int x, int y, int i) { super(); this.x = x; this.y = y; this.i = i; } @Override public int compareTo(Target o) {//因为这道题的特殊性质所以在同一个x值下是不可能有两个圆盘同时出现的,这样重载就行了 if(x<o.x) return -1; if(x>o.x) return 1; return 0; } Boolean inside(int x,int y) { return (this.x-x)*(this.x-x)+(this.y-y)*(this.y-y)<this.y*this.y; } } public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n=cin.nextInt(); TreeSet<Target> set=new TreeSet<>(); int mr=0; for(int i=1;i<=n;i++) { int t,x,y; t=cin.nextInt(); x=cin.nextInt(); y=cin.nextInt(); if(t==1) { set.add(new Target(x, y, i)); mr=Math.max(mr, y);//最大的半径 }else { //java的treeset迭代器遍历 Iterator<Target> it = set.subSet(new Target(x-mr, 0, 0), new Target(x+mr, 0, 0)).iterator();//在treeset的这个可能的区间的查找可能命中的原盘,subSet区间左闭右开 int ans=-1; while (it.hasNext()) { Target next=it.next(); if(next.inside(x, y)) { ans=next.i; set.remove(next); break; } } System.out.println(ans); } } cin.close(); }}
阅读全文
0 0
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- 测试与开发(二)
- BZOJ 1273: [BeiJingWc2008]序列
- 【Mysql】too many connections 错误
- Tensor Flow 小试牛刀(回归模型)
- vue组件实现Tab切换功能
- Gym
- jquery之同级,父级,子级间元素的添加移除
- numpy.random.seed()方法的作用
- 看书总结
- 用Python写自己的layer
- 顺序表应用7:最大子段和之分治递归法
- 图像对比度的原理
- netty源码分析之服务端启动全
- 部署dubbo监控中心