Link
CF1905 A Constructive Problems
Question
有一个 \(N\times M\) 的矩阵,你需要建造一些房子,把这个矩阵填满
-
当一个 \(2\times 2\) 的正方形左上和右下有房子时,左下和右上房子会自动生成
-
当一个 \(2\times 2\) 的正方形左下和右上有房子时,左上和右下房子会自动生成
问你需要造的最少房子数
Solution
考虑到一行如果需要房子,那么肯定至少有一个房子时自己造的,如果一列有房子,那么至少一个是自己造的,所以答案是 \(\max(n,m)\)
Code
#include<bits/stdc++.h>
using namespace std;
int read(){
int ret=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')f=-f;ch=getchar();}
while(ch<='9'&&ch>='0')ret=ret*10+ch-'0',ch=getchar();
return ret*f;
}
void solve(){
int a=read(),b=read();
printf("%d\n",max(a,b));
}
int main(){
freopen("A.in","r",stdin);
int T=read();;
while(T--) solve();
}