Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <fstream>
  2. #define nmax 101
  3. #define kmax 41
  4.  
  5. using namespace std;
  6.  
  7. short modul(short x)
  8. {
  9. if (x<0) return -x;
  10. else return x;
  11. }
  12.  
  13. short max(short x,short y)
  14. {
  15. if (x>=y) return x;
  16. else return y;
  17. }
  18.  
  19. short min(short x,short y)
  20. {
  21. if (x>=y) return y;
  22. else return x;
  23. }
  24.  
  25. int main()
  26. {
  27. short t[nmax][nmax],sol[nmax],m,n,k,x1,y1,x2,y2,v,i,j,pg,ne=0,l,c,tip,d;
  28.  
  29. ifstream f("elicop.in");
  30. ofstream g("elicop.out");
  31.  
  32. //initializez vectorul de solutii
  33. for(i=0;i<kmax;i++) sol[i]=0;
  34.  
  35. // citesc datele de intrare
  36. f>>m>>n;
  37. for(i=1;i<=m;i++)
  38. for(j=1;j<=n;j++)
  39. f>>t[i][j];
  40. f>>k;
  41.  
  42. for(i=1;i<=k;i++)
  43. {
  44. f>>x1>>y1>>x2>>y2>>v;
  45. d=(x2-x1)*(y2-y1);
  46. if (d>0&&v==-1) tip=1;
  47. if (d>0&&v==1) tip=2;
  48. if (d<0&&v==1) tip=3;
  49. if (d<0&&v==-1) tip=4;
  50. pg=0;
  51. switch (tip)
  52. {
  53. case 1 : {for(l=1;l<=max(x1,x2)-min(x1,x2)+1;l++)
  54. for(c=1;c<=l;c++)
  55. if (t[l+min(x1,x2)-1][c+min(y1,y2)-1]==0) pg++;
  56. break;
  57. }
  58. case 2 : {for(l=1;l<=max(x1,x2)-min(x1,x2)+1;l++)
  59. for(c=l;c<=max(y1,y2)-min(y1,y2)+1;c++)
  60. if (t[l+min(x1,x2)-1][c+min(y1,y2)-1]==0) pg++;
  61. break;
  62. }
  63. case 3 : {for(l=1;l<=max(x1,x2)-min(x1,x2)+1;l++)
  64. for(c=1;c<=modul(x2-x1)+2-l;c++)
  65. if (t[l+min(x1,x2)-1][c+min(y1,y2)-1]==0) pg++;
  66. break;
  67. }
  68. case 4 : {for(l=1;l<=max(x1,x2)-min(x1,x2)+1;l++)
  69. for(c=modul(x2-x1)+2-l;c<=max(y1,y2)-min(y1,y2)+1;c++)
  70. if (t[l+min(x1,x2)-1][c+min(y1,y2)-1]==0) pg++;
  71. break;
  72. }
  73. }
  74. if (pg==0) ne++;
  75. else
  76. if (pg>(modul(x2-x1)+1)*(modul(x2-x1)+2)/4) sol[++sol[0]]=i;
  77.  
  78. }
  79. g<<ne<<"\n";
  80. g<<sol[0]<<" ";
  81. for(i=1;i<=sol[0];i++) g<<sol[i]<<" ";
  82.  
  83. f.close();
  84. g.close();
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement