fork download
  1. #include <cstdio>
  2.  
  3. long long a, b;
  4. long long x1[2002], y1[2002];
  5.  
  6. int process(int jj) {
  7.  
  8. long long i, j, n, m, l, c=0, xx, yy, jy, x, y, temp, pj, min, check;
  9.  
  10. scanf("%lld%lld%lld",&n,&m,&l);
  11. if(m>2000)
  12. return 0;
  13. for(i=0; i<=m; i++)
  14. scanf("%lld%lld",&x1[i],&y1[i]);
  15.  
  16. for(i=0; i<m; i++)
  17. for(j=i+1; j<=m; j++)
  18. if(x1[i] > x1[j]) {
  19. temp = x1[i];
  20. x1[i] = x1[j];
  21. x1[j] = temp;
  22. temp = y1[i];
  23. y1[i] = y1[j];
  24. y1[j] = temp;
  25. }
  26.  
  27. xx = x1[0], yy = y1[0];
  28. for(i=1; i<=m; i++) {
  29. x = x1[i], y = y1[i];
  30. for(j=xx; j<=x; j++) {
  31. if(yy < y) {
  32. jy = yy + j - xx;
  33. a = j - jy;
  34. b = j + jy;
  35. }
  36. else {
  37. jy = yy - j - xx;
  38. a = j - jy;
  39. b = j + jy;
  40. }
  41. if(a<=0 && b>=n && (c==0 || c==2)) {
  42. if(c==0) {
  43. min = b - a;
  44. pj = jy;
  45. c = 2;
  46. if((j-jy)%2==0)
  47. check = 0;
  48. else
  49. check = 1;
  50. }
  51. else if(c==2 && min > b-a) {
  52. min = b - a;
  53. pj = jy;
  54. if((j-jy)%2==0)
  55. check = 0;
  56. else
  57. check = 1;
  58. }
  59. }
  60. }
  61. xx = x;
  62. yy = y;
  63. }
  64.  
  65. if(c==2 && check==0)
  66. printf("Case #%lld\n%lld 1\n",jj,pj);
  67. else if(c==2 && check==1)
  68. printf("Case #%lld\n%lld 2\n",jj,pj*2-1);
  69.  
  70. if(c==0)
  71. printf("Case #%lld\n-1\n",jj);
  72.  
  73. return 0;
  74. }
  75.  
  76. int main() {
  77.  
  78. setbuf(stdout, NULL);
  79.  
  80. int T, jj;
  81.  
  82. scanf("%d",&T);
  83. for(jj=1; jj<=T; jj++) {
  84. process(jj);
  85. }
  86.  
  87. return 0;
  88. }
Success #stdin #stdout 0s 4236KB
stdin
2
8 2 1
0 1
4 5
8 1
10 1 1
0 10
5 5
stdout
Case #1
9 2
Case #2
5 1