ural 1052. Rabbit Hunt hash
来源:互联网 发布:初学者学化妆知乎 编辑:程序博客网 时间:2024/06/10 14:58
1052. Rabbit Hunt
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
A good hunter kills two rabbits with one shot. Of course, it can be easily done since for any two points we can always draw a line containing the both. But killing three or more rabbits in one shot is much more difficult task. To be the best hunter in the world one should be able to kill the maximal possible number of rabbits. Assume that rabbit is a point on the plane with integer x and ycoordinates. Having a set of rabbits you are to find the largest number of rabbits that can be killed with single shot, i.e. maximum number of points lying exactly on the same line. No two rabbits sit at one point.
Input
An input contains an integer N (3 ≤ N ≤ 200) specifying the number of rabbits. Each of the next N lines in the input contains the x coordinate and the y coordinate (in this order) separated by a space (−2000 ≤ x, y ≤ 2000).
Output
The output contains the maximal number of rabbits situated in one line.
Sample
67 1228 1399 15610 17311 190-100 1
5
Problem Author: Stanislav Vasilyev
Problem Source: Ural State University collegiate programming contest (25.03.2000)
Problem Source: Ural State University collegiate programming contest (25.03.2000)
import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.io.PrintWriter;import java.math.BigInteger;import java.util.HashMap;import java.util.StringTokenizer;public class Main {public static void main(String[] args) {new Task().solve();}}class Task {InputReader in = new InputReader(System.in);PrintWriter out = new PrintWriter(System.out);class Node{int x , y ;Node(int x , int y){if(x != 0){int g = gcd(Math.abs(x) , Math.abs(y)) ; x /= g ; y /= g ; if(x < 0 && y < 0){ x = -x ; y = -y ; }}else{y = 10000 ;}this.x = x ;this.y = y ;}int gcd(int x , int y){return y == 0 ? x : gcd(y , x%y) ;}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result + getOuterType().hashCode();result = prime * result + x;result = prime * result + y;return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;Node other = (Node) obj;if (!getOuterType().equals(other.getOuterType()))return false;if (x != other.x)return false;if (y != other.y)return false;return true;}private Task getOuterType() {return Task.this;} }void put(HashMap<Node , Integer> hash , Node node){Integer cnt = hash.get(node) ;hash.put(node, cnt == null ? 1 : cnt+1) ;}void solve() {HashMap<Node , Integer> hash = new HashMap<Node, Integer>() ;int n = in.nextInt() ;int[][] p = new int[n][2] ;for(int i = 0 ; i < n ; i++){p[i][0] = in.nextInt() ;p[i][1] = in.nextInt() ;}int res = 0 ;for(int o = 0 ; o < n ; o++){hash.clear() ;int cnt = 1 ;for(int i = 0 ; i < n ; i++){if(i == o){continue ;}put(hash, new Node(p[i][0] - p[o][0] , p[i][1] - p[o][1])) ;}for(int c : hash.values()){cnt = Math.max(c , cnt) ;}res = Math.max(res , cnt+1) ;}out.println(res) ;out.flush() ;}}class InputReader {public BufferedReader reader;public StringTokenizer tokenizer;public InputReader(InputStream stream) {reader = new BufferedReader(new InputStreamReader(stream), 32768);tokenizer = new StringTokenizer("");}private void eat(String s) {tokenizer = new StringTokenizer(s);}public String nextLine() {try {return reader.readLine();} catch (Exception e) {return null;}}public boolean hasNext() {while (!tokenizer.hasMoreTokens()) {String s = nextLine();if (s == null)return false;eat(s);}return true;}public String next() {hasNext();return tokenizer.nextToken();}public int nextInt() {return Integer.parseInt(next());}public int[] nextInts(int n) {int[] nums = new int[n];for (int i = 0; i < n; i++) {nums[i] = nextInt();}return nums;}public long nextLong() {return Long.parseLong(next());}public double nextDouble() {return Double.parseDouble(next());}public BigInteger nextBigInteger() {return new BigInteger(next());}}
阅读全文
0 0
- ural 1052. Rabbit Hunt hash
- ural 1052 Rabbit Hunt
- timus 1052. Rabbit Hunt URAL 解题报告 多点共线问题
- 1052. Rabbit Hunt
- 1052. Rabbit Hunt
- POJ 2606 / URAL 1502 Rabbit hunt (计算几何)
- URAL 1849|Rabbit Hunt 2|计算几何|二分|Set
- pku2606 Rabbit hunt
- Rabbit hunt(P2606)
- poj 2606 Rabbit hunt
- Timus 1052 Rabbit Hunt
- POJ2606 Rabbit hunt
- poj2606 Rabbit hunt(叉积)
- poj 2606 Rabbit hunt
- poj Rabbit hunt
- 【POJ 2606】Rabbit hunt
- Poj2606 Rabbit hunt
- poj P2606 Rabbit hunt
- maven的eclipse插件在增加依赖(Add Dependency)时无法搜索远程仓库
- 腾讯重磅发布AI小微,机智云国内首家云对云打通
- js计算日期时间
- 486. Predict the Winner
- 谈谈步进电机的优点与缺点
- ural 1052. Rabbit Hunt hash
- 密码学
- return false,preventDefault,stopPropagation的用法对比
- 什么是 秘钥延伸(Key Stretching)
- Python迭代器与生成器
- AJAX实现分页及动态增删操作
- HDU1392 Surround the Trees(凸包模版题)
- CSS权重计算问题
- python数据分析学习路线