Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
You have a grid with N rows and M columns. You have two types of tiles — one of dimensions 2×2 and the other of dimensions 1×1. You want to cover the grid using these two types of tiles in such a way that:
Find the minimum number of 1×1 tiles you have to use to fill the grid.
For each test case, print on a new line the minimum number of 1×1 tiles needed to fill the grid.
Input:
4
1 1
4 5
6 8
3 2
Output:
1
4
0
2
Test case 1: There is only one square in the grid, and it must be filled with a single 1×1 tile.
Test case 2: One way of tiling the grid using 1×1 tiles exactly 4 times is as follows:
Test case 3: One way of tiling the grid using no 1×1 tiles is as follows:
Test case 4: One way of tiling the grid using 1×1 tiles exactly twice is:
# cook your dish here
for _ in range(int(input())):
x,y=map(int,input().split())
if x%2==0 and y%2==0:
print(0)
elif x%2!=0 and y%2!=0:
print(x+y-1)
else:
if x%2==0:
print(x)
else:
print(y)
#include <iostream>
using namespace std;
int main() {
int t,n,m;
cin>>t;
while(t--)
{
cin>>n>>m;
int tile2=(n/2)*(m/2);
int remaining=(n*m)-(tile2*4);
cout<<remaining<<endl;
}
return 0;
}
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{
int n=sc.nextInt();
int m=sc.nextInt();
int n1=n%2;
int m1=m%2;
n1*=m;
m1*=n;
int c=n1+m1;
if(n1!=0 && m1!=0)
{
c=c-1;
}
System.out.println(c);
t--;
}
}
}
In our experience, we suggest you solve this Fill The Grid CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Fill The Grid CodeChef Solution
I hope this Fill The Grid CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>