Advertisement
raisul82

LIGHTOJ 1010 - Knights in Chessboard

Jul 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int r,c,t,result,i=0,f;
  6. scanf("%d",&t);
  7. while(t-- && scanf("%d%d",&r,&c)==2)
  8. {
  9. if(r==1 || c==1)
  10. {
  11. if(r>c)
  12. {
  13. result=r;
  14. }
  15. else
  16. {
  17. result=c;
  18. }
  19.  
  20. }
  21. else if(r==2 || c==2)
  22. {
  23. if(r>c)
  24. {
  25. f=r;
  26. }
  27. else
  28. {
  29. f=c;
  30. }
  31.  
  32. if(r==2 && c==2)
  33. {
  34. result=4;
  35. }
  36. else if(f%2==0 && f%4!=0)
  37. {
  38. result=f+2;
  39. }
  40. else if(f%2!=0)
  41. {
  42. result=f+1;
  43. }
  44.  
  45. }
  46.  
  47. else
  48. {
  49. result=ceil((float)(r*c)/2);
  50. }
  51.  
  52. printf("Case %d: %d\n",++i,result);
  53.  
  54. }
  55. return 0;
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement