fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main (String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int l = scanner.nextInt();
  7. int n = scanner.nextInt();
  8. int k = scanner.nextInt();
  9. int count = 0;
  10. for(int i=0; i<n; i++) {
  11. int x1 = scanner.nextInt();
  12. int y1 = scanner.nextInt();
  13. int x2 = scanner.nextInt();
  14. int y2 = scanner.nextInt();
  15. if(x1*x1+y1*y1<=l*l||x2*x2+y2*y2<=l*l)
  16. count++;
  17. else {
  18. int a, b, c;
  19. int deltaX=x2-x1;
  20. int deltaY=y2-y1;
  21. a=deltaY;
  22. b=-deltaX;
  23. c=y1*deltaX-x1*deltaY;
  24. if(c*c<=l*l*(a*a+b*b)&&(-c*b<=(b*b+a*a)*Math.max(y2, y1)&&-c*b>=(b*b+a*a)*Math.min(y2, y1)))
  25. count++;
  26. }
  27. }
  28. System.out.println(count/k+1);
  29. }
  30. }
Success #stdin #stdout 0.07s 2184192KB
stdin
4 4 2
1 1 -1 3
2 2 4 2
-3 -4 -3 4
1 -5 4 -4
stdout
2