ural 1052. Rabbit Hunt hash

来源:互联网 发布:初学者学化妆知乎 编辑:程序博客网 时间:2024/06/10 14:58

1052. Rabbit Hunt

Time limit: 1.0 second
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 ≤ xy ≤ 2000).

Output

The output contains the maximal number of rabbits situated in one line.

Sample

inputoutput
67 1228 1399 15610 17311 190-100 1
5
Problem Author: Stanislav Vasilyev 
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());}}





原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 在部队被欺负了怎么办 衣服上的标志洗掉了怎么办 整件白衬衣被染怎么办 遇到敲诈小混混该怎么办 纯棉衣服洗长了怎么办 纯棉的衣服洗后长了怎么办 睡觉把脖子扭了怎么办 微信限额10万了怎么办 新兵条令背不下来怎么办 武警部队改革去年入伍的新兵怎么办 规培考试没考上怎么办 规培如果没考上怎么办 农民工集体讨薪 领导不在怎么办 卷闸门钥匙丢了怎么办 邻居把路堵了该怎么办 邻居家的盆栽对准我家大门怎么办 袜子掉到了楼下的阳台怎么办? 合租房没有阳台晒衣服怎么办 车门锁了钥匙在里面怎么办 邻居忘带钥匙你看见会怎么办 把车钥匙锁车里了怎么办 偷了东西不承认怎么办 孩子偷了东西不承认怎么办 公司员工偷了东西不承认怎么办 知道被谁偷了没有证据怎么办 被贼偷了知道是谁没有证据怎么办 前任要去部队闹怎么办 站久了腿粗怎么办 机械表表带长了怎么办 恶魔之眼褪色了怎么办 恶魔之眼掉色后怎么办 练瑜伽出汗瑜伽垫手滑怎么办 cf多出来的神器怎么办 脖子痛得低不了怎么办 六岁的孩孑不吃.饭怎么办 大腿肌肉练废了怎么办 吃鸡里的信誉分太低怎么办she 血压高老是晕怎么办27 我腰疼的厉害怎么办 奥克斯空调外机上霜风扇不转怎么办 燃脂膏辣辣的怎么办