Advertisement
juanjo12x

UVA_696_How_Many_Knights

Jul 26th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<cstring>
  6. #include<algorithm>
  7.  
  8.  
  9.  
  10. #include<string>
  11. #include<vector>
  12. #include<map>
  13. #include<queue>
  14. #include<stack>
  15.  
  16.  
  17. #define loop(i, n) for(int i=0; i<n; i++)
  18. #define loopfrom1(i, n) for(int i=1; i<n; i++)
  19. #define mem(array, value) memset(array, value, sizeof(array))
  20. #define MIN(a, b) (a<b?a:b)
  21. #define MAX(a, b) (a>b?a:b)
  22. #define pb(a) push_back(a)
  23. #define SZ size()
  24. #define getint(n) scanf("%d", &n)
  25. #define pi acos(-1.0)
  26. #define inf 536870912         // 1<<29
  27. #define debug cout<<"ok"<<endl
  28. #define ll long long int
  29. #define mod(a) (a>0?a:-a)
  30. #define Read(filename) freopen(filename, "r", stdin)
  31.  
  32.  
  33. using namespace std;
  34.  
  35.  
  36. int f(int x)
  37. {
  38.     if(x == 1) return 2;
  39.     if(x == 2 || x == 3) return 4;
  40.     return 0;
  41. }
  42.  
  43.  
  44.  
  45. int main()
  46. {
  47.     int x, y, z;
  48.     while(true)
  49.     {
  50.         getint(x);
  51.         getint(y);
  52.  
  53.         if(x == 0 && y == 0) break;
  54.  
  55.  
  56.  
  57.         if(x == 1 || y == 1)
  58.         {
  59.             z = x * y;
  60.         }
  61.         else
  62.         {
  63.             if(x == 2 || y == 2)
  64.             {
  65.                 z = (x*y)/2;
  66.                 z = int(z/4) * 4 + f(z%4);
  67.             }
  68.             else
  69.             {
  70.                 z = x * y;
  71.                 z = (z+1)/2;
  72.             }
  73.         }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.         printf("%d knights may be placed on a %d row %d column board.\n",z, x, y);
  80.     }
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement