fork download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Main {
  6. static int i,j,n,m,x[] = new int[2505],y[] = new int[2505];
  7. static int a[] = new int[4100005];
  8. static Map<Long, Integer> hashmap = new HashMap<Long, Integer>();
  9. static int gcd(int a, int b)
  10. {
  11. if (b == 0) return a;
  12. return gcd(b,a%b);
  13. }
  14. static int Abs(int x)
  15. {
  16. if (x > 0)
  17. return x;
  18. return -x;
  19. }
  20. public static void main(String[] args) throws IOException{
  21. Scanner sc = new Scanner(System.in);//new File("input.txt"));
  22. PrintWriter pw = new PrintWriter(System.out);//new File("output.txt"));
  23. n = sc.nextInt();
  24. for (i = 2; i <= 2000; i++)
  25. a[i*i-i] = i;
  26. for (i = 0; i < n; i++)
  27. {
  28. x[i] = sc.nextInt(); y[i] = sc.nextInt();
  29. }
  30. for (i = 0; i < n; i++)
  31. {
  32. for (j = 0; j < n; j++)
  33. if (i != j)
  34. {
  35. int kc = y[j] - y[i];
  36. int kz = x[j] - x[i];
  37. int bc = y[i]*(x[j] - x[i]) - x[i]*(y[j]-y[i]);
  38. int bz = x[j] - x[i];
  39. if (kz != 0)
  40. {
  41. int tmp = gcd(Abs(kc), Abs(kz));
  42. kc /= tmp; kz /= tmp;
  43. if (kc < 0)
  44. {
  45. kc = -kc; kz = -kz;
  46. }
  47. if (kc == 0)
  48. kz = 1;
  49. tmp = gcd(Abs(bc), Abs(bz));
  50. bc /= tmp; bz /= tmp;
  51. if (bc < 0)
  52. {
  53. bc = -bc; bz = -bz;
  54. }
  55. if (bc == 0)
  56. bz = 1;
  57. }
  58. else
  59. kc = bc = x[i];
  60. long hsh = (long)bc*270000*100000 + (long)bz*9000000 + (long)kc*300 + (long)kz;
  61. int k = 0;
  62. if (hashmap.containsKey(hsh))
  63. {
  64. k = hashmap.get(hsh);
  65. }
  66. hashmap.put(hsh, k+2);
  67. }
  68. }
  69. long ans = ((long)n*(n-1)*(n-2))/6;
  70. Iterator <Long> itr = hashmap.keySet().iterator();
  71. while (itr.hasNext())
  72. {
  73. int tmp = hashmap.get(itr.next());
  74. tmp = a[tmp/2];
  75. ans -= ((long)tmp*(tmp-1)*(tmp-2))/6;
  76. }
  77. pw.println(ans);
  78. pw.close();
  79. }
  80. }
  81.  
Runtime error #stdin #stdout #stderr 0.12s 380608KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:907)
	at java.util.Scanner.next(Scanner.java:1530)
	at java.util.Scanner.nextInt(Scanner.java:2160)
	at java.util.Scanner.nextInt(Scanner.java:2119)
	at Main.main(Main.java:23)