题目大意:给出10万条直线,求是否存在交点于x1,x2之间
题目链接:http://codeforces.com/contest/593/problem/B
1 import java.io.*; 2 import java.math.*; 3 import java.util.*; 4 5 public class Main { 6 static class node { 7 long y1, y2; 8 9 node(long a, long b) { 10 y1 = a; 11 y2 = b; 12 } 13 } 14 15 static class cmp implements Comparator<node> { 16 // 从小到大 17 public int compare(node A, node B) { 18 if (A.y1 == B.y1) { 19 if (A.y2 > B.y2) 20 return 1; 21 else 22 return -1; 23 } 24 if (A.y1 > B.y1) 25 return 1; 26 else 27 return -1; 28 } 29 } 30 31 public static void main(String[] argc) { 32 Scanner cin = new Scanner(System.in); 33 int i; 34 node[] p = new node[100005]; 35 while (cin.hasNext()) { 36 long n = cin.nextLong(); 37 long x1 = cin.nextLong(); 38 long x2 = cin.nextLong(); 39 for (i = 0; i < n; i++) { 40 long a = cin.nextLong(); 41 long b = cin.nextLong(); 42 p[i] = new node(a * x1 + b, a * x2 + b); 43 } 44 Arrays.sort(p, 0, (int) n, new cmp()); 45 46 for (i = 1; i < n; i++) { 47 if (p[i].y1 != p[i - 1].y1) 48 if (p[i].y2 < p[i - 1].y2) 49 break; 50 } 51 if (i == n) 52 System.out.println("NO"); 53 else 54 System.out.println("YES"); 55 } 56 } 57 }
原文:http://www.cnblogs.com/zuferj115/p/5001580.html