hdu4022
来源:互联网 发布:vscode js格式化插件 编辑:程序博客网 时间:2024/06/06 07:19
题目大意:给你n个点(二位),坐标范围(<10^9)然后m次询问
0 s 表示询问x = s这条线上有多少个点并删除
1 s 表示询问y = s这条线上有多少个点并删除
import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.io.StreamTokenizer;import java.math.BigInteger;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.LinkedList;import java.util.NavigableSet;import java.util.PriorityQueue;import java.util.Queue;import java.util.Scanner;import java.util.Set;import java.util.SortedSet;import java.util.Stack;import java.util.StringTokenizer;import java.util.TreeSet;import javax.swing.text.NavigationFilter;public class Main { public static void main(String[] args) throws IOException{ StreamTokenizer cin = new StreamTokenizer(new BufferedInputStream(System.in)); InputReader in = new InputReader(System.in) ; PrintWriter out = new PrintWriter(System.out) ; int n , m ; while(true){ n = in.nextInt() ; m = in.nextInt() ; if(n == 0 && m == 0) break ; new Task().solve(n , m , in, out) ; // out.flush() ; out.println(); } out.flush() ; }}class Task{ public void solve(int n , int m , InputReader in , PrintWriter out) throws IOException{ HashMap<Integer , NavigableSet<E>> sx = new HashMap<Integer , NavigableSet<E>>() ; HashMap<Integer , NavigableSet<E>> sy = new HashMap<Integer , NavigableSet<E>>() ; for(int i = 1 ; i <= n ; i++){ int x = in.nextInt() ; int y = in.nextInt() ; if(sx.get(x) == null) sx.put(x, new TreeSet<E>()) ; sx.get(x).add(new E(y, i)) ; if(sy.get(y) == null) sy.put(y, new TreeSet<E>()) ; sy.get(y).add(new E(x, i)) ; } while(m-- > 0){ int k = in.nextInt() ; int d = in.nextInt() ; if(k == 0){ NavigableSet<E> xt = sx.get(d) ; if(xt == null){ out.println(0) ; continue ; } out.println(xt.size()); for(E e : xt){ int y = e.value ; NavigableSet<E>dely = sy.get(y) ; if(dely == null) continue ; E dy ; while((dy = dely.higher(new E(d , -1))) != null && dy.value == d){ dely.remove(dy) ; } } xt.clear(); } else{ NavigableSet<E> yt = sy.get(d) ; if(yt == null){ out.println(0) ; continue ; } out.println(yt.size()); for(E e : yt){ int x = e.value ; NavigableSet<E>delx = sx.get(x) ; if(delx == null) continue ; E dx ; while((dx = delx.higher(new E(d , -1))) != null && dx.value == d){ delx.remove(dx) ; } } yt.clear(); } } }}class E implements Comparable<E>{ int value ; int id ; public int compareTo(E o){ if(value != o.value) return Integer.compare(value, o.value) ; else return Integer.compare(id, o.id) ; } E(int value , int id){ this.value = value ; this.id = id ; }}class InputReader{ public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream){ reader = new BufferedReader(new InputStreamReader(stream), 32768) ; tokenizer = null ; } public String next(){ while(tokenizer == null || ! tokenizer.hasMoreTokens()){ try{ tokenizer = new StringTokenizer(reader.readLine()); }catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); }}
0 0
- hdu4022
- hdu4022
- hdu4022
- HDU4022(二分法)
- hdu4022 离散化
- hdu4022 map+multiset
- hdu4022-bomb stl
- hdu4022 Bombing stl(map+set)
- HDU4022-map+multiset--The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
- 面向对象
- 移动端加密视频的授权播放
- (1)const的位置
- 在max下完全卸载nodejs
- cocos2dx 定时执行任务
- hdu4022
- Deep Learning(Logistic Regression)学习之MNIST C++实现
- css3媒体查询实现网站响应式布局
- 从付费到免费的跨平台游戏引擎Corona
- Maven系列--"maven-compiler-plugin"的使用
- javascript入门笔记(6)——document
- 如何使Linux支持中文字符
- 监听手机键盘输入操作
- Ubuntu 12.04 Mysql数据库文件迁移