fork download
  1. /* package codechef; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8.  
  9. //Note : If you are running this code on codechef then replace Ideone with Codechef
  10. class Ideone //Codechef
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. try{
  15. //write your code here
  16. Scanner sc = new Scanner(System.in);
  17. int t = sc.nextInt();
  18. int maxN = 100;
  19. int[] m = new int[maxN];
  20. int[] R = new int[maxN];
  21. int[] x1 = new int[maxN];
  22. int[] y1 = new int[maxN];
  23. int[] x2 = new int[maxN];
  24. int[] y2 = new int[maxN];
  25. int[] z = new int[maxN];
  26. int[] a = new int[maxN];
  27. int[] b = new int[maxN];
  28. int[] c = new int[maxN];
  29. int[] f = new int[maxN];
  30. int h=0;
  31. int temp=0;
  32. int e=0;
  33. int v=0;
  34. while(t > 0){
  35.  
  36. int n = sc.nextInt();
  37. int r = sc.nextInt();
  38. for(int i=0;i<n;i++){
  39. R[i] = sc.nextInt();
  40. z[i]=i+1;
  41. }
  42. for(int i=0;i<n;i++){
  43. if(i+1==n)
  44. break;
  45. else
  46. e=z[i+1]-z[i];
  47. if(e==0){
  48. f[i]=0;
  49. }
  50. else{
  51. f[i]=(R[i+1]-R[i])/e;
  52. }
  53. }
  54.  
  55. for(int i=0;i<r;i++){
  56. x1[i] = sc.nextInt();
  57. x2[i] = sc.nextInt();
  58. y1[i] = sc.nextInt();
  59. y2[i] = sc.nextInt();
  60. v=(x2[i]-x1[i]);
  61. if(v==0){
  62. m[i]=0;
  63. }
  64. else{
  65. m[i]=(y2[i]-y1[i])/(x2[i]-x1[i]);
  66. }
  67. }
  68. for(int i=0;i<r;i++){
  69.  
  70. temp=m[i];
  71. for(int j=0;j<n;j++){
  72.  
  73. if((temp==f[j])&&(j<n-1)){
  74. h=h+1;
  75. }
  76. }
  77. System.out.println(h);
  78. h=0;
  79. }
  80. t--;
  81. }//end of test case loop
  82.  
  83. }//end of try block
  84. catch(Exception e){
  85.  
  86. }
  87. }//end of main function
  88.  
  89. }
Success #stdin #stdout 0.1s 35256KB
stdin
1
5 3
1 2 3 4 5
1 2 3 4
2 3 3 3
2 5 7 10
stdout
4
0
4