Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int quick_power (int a, int n)
  5. {
  6. int r=1;
  7. while (n>0)
  8. {
  9. if (n%2==1)
  10. {
  11. r*=a;
  12. n--;
  13. }
  14. a*=a;
  15. n/=2;
  16. }
  17. return r;
  18. }
  19. int main()
  20. {
  21. int n,m,c,i,j,x1,x2,xm,s,d,ch,ch1=0;
  22. cin >> n >> m;
  23. int a[2*n][2*n], b[n];
  24. for (i=0;i<2*n;i++)
  25. {
  26. for (j=0;j<2*n;j++)
  27. {
  28. a[i][j]=0;
  29. }
  30. }
  31. for (j=0;j<n;j++)
  32. {
  33. b[j]=quick_power(2,j);
  34. }
  35. s=quick_power(2,n);
  36. for (i=0;i<m;i++)
  37. {
  38. cin >> x1 >> x2;
  39. xm=min(x1,x2);
  40. x1=max(x1,x2);
  41. if (xm<0)
  42. xm=xm+n;
  43. else
  44. xm=xm+n-1;
  45. if (x1<0)
  46. x1=x1+n;
  47. else
  48. x1=x1+n-1;
  49. a[xm][x1]=1;
  50. }
  51. for (i=0;i<s;i++)
  52. {
  53. ch=0;
  54. for (c=0;c<2*n;c++)
  55. {
  56. if (ch==0)
  57. {
  58. for (d=c;d<2*n;d++)
  59. {
  60. if (d+c!=2*n-1 && a[c][d]==1)
  61. {
  62. if (c<n)
  63. {
  64. x1=(i/b[n-c-1]+1)%2;
  65. }
  66. else
  67. {
  68. x1=(i/b[c-n])%2;
  69. }
  70. if (d<n)
  71. {
  72. x2=(i/b[n-d-1]+1)%2;
  73. }
  74. else
  75. {
  76. x2=(i/b[d-n])%2;
  77. }
  78. if (x1==0 && x2==0)
  79. {
  80. ch=1;
  81. break;
  82. }
  83.  
  84. }
  85. }
  86. }
  87. }
  88. if (c==2*n && d==2*n)
  89. {
  90. ch1=1;
  91. break;
  92. }
  93. }
  94. if (ch1==1)
  95. cout << "NO" << endl;
  96. else
  97. cout << "YES" << endl;
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement