Problem id : LOJ 1010
To maximize the number of knights we have to place knights in a particular pattern.
Code :
To maximize the number of knights we have to place knights in a particular pattern.
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include<stdio.h> int main() { int tc,cas = 0 ; int ans = 0; scanf("%d",&tc); while(tc--) { int m,n; scanf("%d %d",&m,&n); //ans = solve(m,n); //ROW / COL = 1 if(m==1) ans = n; else if(n==1) ans = m; //ROW / COL = 2 else if(m==2) { ans = 0; for(int i=1,cn=1; i<=n; i+=4,cn++) { // if(cn&1) { if(i==n) ans +=2; else ans += 4; } } } else if(n==2) { ans = 0; for(int i=1,cn=1; i<=m; i+=4,cn++) { // if(cn&1) { if(i==m) ans +=2; else ans += 4; } } } //ROW / COL > 2 else if(m&1)//odd { if(n&1)//odd ans= (m/2 + 1)*(n/2 + 1) + (m/2)*(n/2); else //m odd n even ans= (m/2 + 1)*(n/2) + (m/2)*(n/2); } else { if(n&1)//odd ans= (m/2)*(n/2 + 1) + (m/2)*(n/2); else ans= (m/2)*(n/2) + (m/2)*(n/2); } printf("Case %d: %d\n",++cas,ans); } return 0; } |
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন